Skip to content

Commit

Permalink
cms changes
Browse files Browse the repository at this point in the history
  • Loading branch information
smuzaffar committed Jan 30, 2025
1 parent b332378 commit 7ad08a7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build/parseSpec.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static OFI_t * pushOFI(rpmSpec spec, const char *fn)
ofi->fp = NULL;
ofi->fileName = xstrdup(fn);
ofi->lineNum = 0;
ofi->readBufLen = BUFSIZ;
ofi->readBufLen = BUFSIZ*40;
ofi->readBuf = (char *)xmalloc(ofi->readBufLen);
ofi->readBuf[0] = '\0';
ofi->readPtr = NULL;
Expand Down
5 changes: 1 addition & 4 deletions build/rpmfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,7 @@ int rpmfcExec(ARGV_const_t av, StringBuf sb_stdin, StringBuf * sb_stdoutp,

static void argvAddUniq(ARGV_t * argvp, const char * key)
{
if (argvSearch(*argvp, key, NULL) == NULL) {
argvAdd(argvp, key);
argvSort(*argvp, NULL);
}
argvSortedInsert(argvp, key);
}

#define hasAttr(_a, _n) (argvSearch((_a), (_n), NULL) != NULL)
Expand Down
12 changes: 12 additions & 0 deletions include/rpm/argv.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ int argiAdd(ARGI_t * argip, int ix, int val);
*/
int argvAdd(ARGV_t * argvp, const char *val);

/**\ingroup rpmargv
* If the string is not present in the argv array, add it so that ordering
* of array elements is still stricly growing.
* @retval *argvp argv array
* @param val string arg to insert
* @return 0 always
*
* FIXME: do a binary search to find the insertion point,
* rather than a linear one.
*/
int argvSortedInsert(ARGV_t *argvp, const char *val);

/** \ingroup rpmargv
* Add a string to an argv array, does not need to be nil-terminated.
* @param[out] *argvp argv array
Expand Down
14 changes: 1 addition & 13 deletions lib/rpmchroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ int rpmChrootIn(void)
if (rootState.chrootDone > 0) {
rootState.chrootDone++;
} else if (rootState.chrootDone == 0) {
rpmlog(RPMLOG_DEBUG, "entering chroot %s\n", rootState.rootDir);
if (chdir("/") == 0 && chroot(rootState.rootDir) == 0) {
rootState.chrootDone = 1;
} else {
rpmlog(RPMLOG_ERR, _("Unable to change root directory: %m\n"));
rc = -1;
}
rootState.chrootDone = 1;
}
return rc;
}
Expand All @@ -96,13 +90,7 @@ int rpmChrootOut(void)
if (rootState.chrootDone > 1) {
rootState.chrootDone--;
} else if (rootState.chrootDone == 1) {
rpmlog(RPMLOG_DEBUG, "exiting chroot %s\n", rootState.rootDir);
if (chroot(".") == 0 && fchdir(rootState.cwd) == 0) {
rootState.chrootDone = 0;
} else {
rpmlog(RPMLOG_ERR, _("Unable to restore root directory: %m\n"));
rc = -1;
}
}
return rc;
}
Expand Down
37 changes: 37 additions & 0 deletions rpmio/argv.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,43 @@ int argvSort(ARGV_t argv, int (*compar)(const void *, const void *))
return 0;
}

int argvSortedInsert(ARGV_t *argvp, const char *val)
{
ARGV_t argv;
int argc;
int i;
int comp;
if (argvp == NULL)
return -1;
argc = argvCount(*argvp);
argv = *argvp;
for (i = 0; i != argc; ++i)
{
comp = strcmp(val, argv[i]);
// String already in the list. Do not add.
if (!comp)
return 0;
// String can be inserted at position i. Move items in
// range [i, argc) to range [i+1, argc + 1) and then exit
// the loop.
if (comp < 0)
{
*argvp = xrealloc(*argvp, (argc + 1 + 1) * sizeof(argvp));
argv = *argvp;
memmove(argv + i + 1, argv + i, sizeof(*argv) * (argc-i+1));
argv[i] = xstrdup(val);
return 0;
}
}

// String has to be inserted at the end.
*argvp = xrealloc(*argvp, (argc + 1 + 1) * sizeof(argvp));
argv = *argvp;
argv[argc] = xstrdup(val);
argv[argc + 1] = NULL;
return 0;
}

ARGV_t argvSearch(ARGV_const_t argv, const char *val,
int (*compar)(const void *, const void *))
{
Expand Down
2 changes: 1 addition & 1 deletion rpmio/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#endif
#define iseol(_c) ((_c) == '\n' || (_c) == '\r')

#define MACROBUFSIZ (BUFSIZ * 2)
#define MACROBUFSIZ (BUFSIZ * 40)

#include <rpm/rpmio.h>
#include <rpm/rpmstring.h>
Expand Down

0 comments on commit 7ad08a7

Please sign in to comment.