rpm 5.2.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

misc.c
Go to the documentation of this file.
1
5 #include "system.h"
6
7 #include <rpmversion.h>
8 #include <rpmiotypes.h>
9 #include <rpmlog.h>
10 #include <rpmurl.h>
11 #include <rpmmacro.h> /* XXX for rpmGetPath */
12 #include <rpmtypes.h>
13 #include "misc.h"
14 #include "debug.h"
15
16 /*@unchecked@*/ /*@observer@*/
17 const char * RPMVERSION = VERSION;
18
19 rpmRC rpmMkdirPath (const char * dpath, const char * dname)
20 {
21 struct stat st;
22 int rc;
23
24 if ((rc = Stat(dpath, &st)) < 0) {
25 int ut = urlPath(dpath, NULL);
26 switch (ut) {
27 case URL_IS_PATH:
28 case URL_IS_UNKNOWN:
29 if (errno != ENOENT)
30 break;
31 /*@fallthrough@*/
32 case URL_IS_HTTPS:
33 case URL_IS_HTTP:
34 case URL_IS_FTP:
35 rc = Mkdir(dpath, 0755);
36 break;
37 case URL_IS_DASH:
38 case URL_IS_HKP:
39 break;
40 }
41 if (rc < 0) {
42 rpmlog(RPMLOG_ERR, _("cannot create %%%s %s\n"), dname, dpath);
43 return RPMRC_FAIL;
44 }
45 }
46 return RPMRC_OK;
47 }
48
49 int doputenv(const char *str)
50 {
51 char * a;
52
53 /* FIXME: this leaks memory! */
54 a = xmalloc(strlen(str) + 1);
55 strcpy(a, str);
56 return putenv(a);
57 }
58
59 int dosetenv(const char * name, const char * value, int overwrite)
60 {
61 char * a;
62
63 if (!overwrite && getenv(name)) return 0;
64
65 /* FIXME: this leaks memory! */
66 a = xmalloc(strlen(name) + strlen(value) + sizeof("="));
67 (void) stpcpy( stpcpy( stpcpy( a, name), "="), value);
68 return putenv(a);
69 }
70
71 char * currentDirectory(void)
72 {
73 int currDirLen = 0;
74 char * currDir = NULL;
75
76 do {
77 currDirLen += 128;
78 currDir = xrealloc(currDir, currDirLen);
79 memset(currDir, 0, currDirLen);
80 } while (getcwd(currDir, currDirLen) == NULL && errno == ERANGE);
81
82 return currDir;
83 }