7 #include <rpmio_internal.h>
13 /*@access StringBuf @*/
16 * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
17 * @param this memory to free
20 static /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) {
21 if (this) free((void *)this);
25 char * rpmPermsString(int mode)
27 char *perms = xstrdup("----------");
31 else if (S_ISLNK(mode))
33 else if (S_ISFIFO(mode))
35 else if (S_ISSOCK(mode))
37 else if (S_ISCHR(mode))
39 else if (S_ISBLK(mode))
43 if (mode & S_IRUSR) perms[1] = 'r';
44 if (mode & S_IWUSR) perms[2] = 'w';
45 if (mode & S_IXUSR) perms[3] = 'x';
47 if (mode & S_IRGRP) perms[4] = 'r';
48 if (mode & S_IWGRP) perms[5] = 'w';
49 if (mode & S_IXGRP) perms[6] = 'x';
51 if (mode & S_IROTH) perms[7] = 'r';
52 if (mode & S_IWOTH) perms[8] = 'w';
53 if (mode & S_IXOTH) perms[9] = 'x';
56 perms[3] = ((mode & S_IXUSR) ? 's' : 'S');
59 perms[6] = ((mode & S_IXGRP) ? 's' : 'S');
62 perms[9] = ((mode & S_IXOTH) ? 't' : 'T');
68 /**@todo Infinite loops through manifest files exist, operator error for now. */
69 int rpmReadPackageManifest(FD_t fd, int * argcPtr, const char *** argvPtr)
71 StringBuf sb = newStringBuf();
74 const char ** av = NULL;
75 int argc = (argcPtr ? *argcPtr : 0);
76 const char ** argv = (argvPtr ? *argvPtr : NULL);
84 s = fgets(line, sizeof(line) - 1, fdGetFp(fd));
86 /* XXX Ferror check needed */
91 if ((se = strchr(s, '#')) != NULL) *se = '\0';
93 /* Trim white space. */
95 while (se > s && (se[-1] == '\n' || se[-1] == '\r'))
97 while (*s && strchr(" \f\n\r\t\v", *s) != NULL)
99 if (*s == '\0') continue;
101 /* Insure that file contains only ASCII */
107 /* Concatenate next line in buffer. */
110 appendStringBuf(sb, s);
113 if (s == NULL) /* XXX always true */
114 s = getStringBuf(sb);
121 /* Glob manifest items. */
122 rc = rpmGlob(s, &ac, &av);
125 /* Find 1st existing unprocessed arg. */
126 for (i = 0; i < argc; i++)
127 if (argv && argv[i]) break;
129 /* Concatenate existing unprocessed args after manifest contents. */
130 if (argv && i < argc) {
131 int nac = ac + (argc - i);
132 const char ** nav = xcalloc((nac + 1), sizeof(*nav));
135 memcpy(nav, av, ac * sizeof(*nav));
137 memcpy(nav + ac, argv + i, (argc - i) * sizeof(*nav));
140 *argvPtr = argv = _free(argv);
146 /* Save new argc/argv list. */
148 *argvPtr = _free(*argvPtr);
155 if (argvPtr == NULL || (rc != 0 && av)) {
156 for (i = 0; i < ac; i++)
157 av[i] = _free(av[i]);