Remove STRNCPY macro from libalpm

Replaced calls to the STRNCPY macro with the actual strncpy function, and
pacman passes all pactests.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2007-04-29 12:03:09 -04:00
parent ea327cab84
commit a58e17a1d7
9 changed files with 29 additions and 33 deletions

View file

@ -141,7 +141,7 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target)
if(stat(path, &sbuf) || !S_ISDIR(sbuf.st_mode)) { if(stat(path, &sbuf) || !S_ISDIR(sbuf.st_mode)) {
continue; continue;
} }
STRNCPY(name, ent->d_name, PKG_FULLNAME_LEN); strncpy(name, ent->d_name, PKG_FULLNAME_LEN);
/* truncate the string at the second-to-last hyphen, */ /* truncate the string at the second-to-last hyphen, */
/* which will give us the package name */ /* which will give us the package name */
if((ptr = rindex(name, '-'))) { if((ptr = rindex(name, '-'))) {
@ -733,7 +733,7 @@ int _alpm_db_getlastupdate(pmdb_t *db, char *ts)
} else { } else {
char line[256]; char line[256];
if(fgets(line, sizeof(line), fp)) { if(fgets(line, sizeof(line), fp)) {
STRNCPY(ts, line, 15); /* YYYYMMDDHHMMSS */ strncpy(ts, line, 14); /* YYYYMMDDHHMMSS */
ts[14] = '\0'; ts[14] = '\0';
} else { } else {
fclose(fp); fclose(fp);

View file

@ -350,10 +350,10 @@ static alpm_list_t *add_fileconflict(alpm_list_t *conflicts,
return(conflicts); return(conflicts);
} }
conflict->type = type; conflict->type = type;
STRNCPY(conflict->target, name1, PKG_NAME_LEN); strncpy(conflict->target, name1, PKG_NAME_LEN);
STRNCPY(conflict->file, filestr, CONFLICT_FILE_LEN); strncpy(conflict->file, filestr, CONFLICT_FILE_LEN);
if(name2) { if(name2) {
STRNCPY(conflict->ctarget, name2, PKG_NAME_LEN); strncpy(conflict->ctarget, name2, PKG_NAME_LEN);
} else { } else {
conflict->ctarget[0] = '\0'; conflict->ctarget[0] = '\0';
} }

View file

@ -74,7 +74,7 @@ pmdb_t *_alpm_db_new(const char *root, const char *dbpath, const char *treename)
} }
sprintf(db->path, "%s%s%s/", root, dbpath, treename); sprintf(db->path, "%s%s%s/", root, dbpath, treename);
STRNCPY(db->treename, treename, PATH_MAX); strncpy(db->treename, treename, PATH_MAX);
return(db); return(db);
} }

View file

@ -60,12 +60,12 @@ pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdeptype_t type,
RET_ERR(PM_ERR_MEMORY, NULL); RET_ERR(PM_ERR_MEMORY, NULL);
} }
STRNCPY(miss->target, target, PKG_NAME_LEN); strncpy(miss->target, target, PKG_NAME_LEN);
miss->type = type; miss->type = type;
miss->depend.mod = depmod; miss->depend.mod = depmod;
STRNCPY(miss->depend.name, depname, PKG_NAME_LEN); strncpy(miss->depend.name, depname, PKG_NAME_LEN);
if(depversion) { if(depversion) {
STRNCPY(miss->depend.version, depversion, PKG_VERSION_LEN); strncpy(miss->depend.version, depversion, PKG_VERSION_LEN);
} else { } else {
miss->depend.version[0] = 0; miss->depend.version[0] = 0;
} }

View file

@ -58,12 +58,12 @@ pmpkg_t *_alpm_pkg_new(const char *name, const char *version)
} }
if(name && name[0] != 0) { if(name && name[0] != 0) {
STRNCPY(pkg->name, name, PKG_NAME_LEN); strncpy(pkg->name, name, PKG_NAME_LEN);
} else { } else {
pkg->name[0] = '\0'; pkg->name[0] = '\0';
} }
if(version && version[0] != 0) { if(version && version[0] != 0) {
STRNCPY(pkg->version, version, PKG_VERSION_LEN); strncpy(pkg->version, version, PKG_VERSION_LEN);
} else { } else {
pkg->version[0] = '\0'; pkg->version[0] = '\0';
} }
@ -219,9 +219,9 @@ static int parse_descfile(const char *descfile, pmpkg_t *info)
key = _alpm_strtoupper(key); key = _alpm_strtoupper(key);
_alpm_strtrim(ptr); _alpm_strtrim(ptr);
if(!strcmp(key, "PKGNAME")) { if(!strcmp(key, "PKGNAME")) {
STRNCPY(info->name, ptr, sizeof(info->name)); strncpy(info->name, ptr, sizeof(info->name));
} else if(!strcmp(key, "PKGVER")) { } else if(!strcmp(key, "PKGVER")) {
STRNCPY(info->version, ptr, sizeof(info->version)); strncpy(info->version, ptr, sizeof(info->version));
} else if(!strcmp(key, "PKGDESC")) { } else if(!strcmp(key, "PKGDESC")) {
/* /*
char *lang_tmp; char *lang_tmp;
@ -229,32 +229,32 @@ static int parse_descfile(const char *descfile, pmpkg_t *info)
if((lang_tmp = (char *)malloc(strlen(setlocale(LC_ALL, "")))) == NULL) { if((lang_tmp = (char *)malloc(strlen(setlocale(LC_ALL, "")))) == NULL) {
RET_ERR(PM_ERR_MEMORY, -1); RET_ERR(PM_ERR_MEMORY, -1);
} }
STRNCPY(lang_tmp, setlocale(LC_ALL, ""), strlen(setlocale(LC_ALL, ""))); strncpy(lang_tmp, setlocale(LC_ALL, ""), strlen(setlocale(LC_ALL, "")));
if(info->desc_localized && !info->desc_localized->next) { if(info->desc_localized && !info->desc_localized->next) {
*/ */
STRNCPY(info->desc, ptr, sizeof(info->desc)); strncpy(info->desc, ptr, sizeof(info->desc));
/* /*
} else if (ptr && !strncmp(ptr, lang_tmp, strlen(lang_tmp))) { } else if (ptr && !strncmp(ptr, lang_tmp, strlen(lang_tmp))) {
STRNCPY(info->desc, ptr+strlen(lang_tmp)+1, sizeof(info->desc)); strncpy(info->desc, ptr+strlen(lang_tmp)+1, sizeof(info->desc));
} }
FREE(lang_tmp); FREE(lang_tmp);
*/ */
} else if(!strcmp(key, "GROUP")) { } else if(!strcmp(key, "GROUP")) {
info->groups = alpm_list_add(info->groups, strdup(ptr)); info->groups = alpm_list_add(info->groups, strdup(ptr));
} else if(!strcmp(key, "URL")) { } else if(!strcmp(key, "URL")) {
STRNCPY(info->url, ptr, sizeof(info->url)); strncpy(info->url, ptr, sizeof(info->url));
} else if(!strcmp(key, "LICENSE")) { } else if(!strcmp(key, "LICENSE")) {
info->licenses = alpm_list_add(info->licenses, strdup(ptr)); info->licenses = alpm_list_add(info->licenses, strdup(ptr));
} else if(!strcmp(key, "BUILDDATE")) { } else if(!strcmp(key, "BUILDDATE")) {
STRNCPY(info->builddate, ptr, sizeof(info->builddate)); strncpy(info->builddate, ptr, sizeof(info->builddate));
} else if(!strcmp(key, "BUILDTYPE")) { } else if(!strcmp(key, "BUILDTYPE")) {
STRNCPY(info->buildtype, ptr, sizeof(info->buildtype)); strncpy(info->buildtype, ptr, sizeof(info->buildtype));
} else if(!strcmp(key, "INSTALLDATE")) { } else if(!strcmp(key, "INSTALLDATE")) {
STRNCPY(info->installdate, ptr, sizeof(info->installdate)); strncpy(info->installdate, ptr, sizeof(info->installdate));
} else if(!strcmp(key, "PACKAGER")) { } else if(!strcmp(key, "PACKAGER")) {
STRNCPY(info->packager, ptr, sizeof(info->packager)); strncpy(info->packager, ptr, sizeof(info->packager));
} else if(!strcmp(key, "ARCH")) { } else if(!strcmp(key, "ARCH")) {
STRNCPY(info->arch, ptr, sizeof(info->arch)); strncpy(info->arch, ptr, sizeof(info->arch));
} else if(!strcmp(key, "SIZE")) { } else if(!strcmp(key, "SIZE")) {
/* size in the raw package is uncompressed (installed) size */ /* size in the raw package is uncompressed (installed) size */
info->isize = atol(ptr); info->isize = atol(ptr);
@ -494,7 +494,7 @@ int _alpm_pkg_splitname(const char *target, char *name, char *version, int witha
} else { } else {
t++; t++;
} }
STRNCPY(tmp, t, PKG_FULLNAME_LEN+7); strncpy(tmp, t, PKG_FULLNAME_LEN+7);
/* trim file extension (if any) */ /* trim file extension (if any) */
if((p = strstr(tmp, PM_EXT_PKG))) { if((p = strstr(tmp, PM_EXT_PKG))) {
*p = '\0'; *p = '\0';
@ -518,12 +518,12 @@ int _alpm_pkg_splitname(const char *target, char *name, char *version, int witha
return(-1); return(-1);
} }
if(version) { if(version) {
STRNCPY(version, p+1, PKG_VERSION_LEN); strncpy(version, p+1, PKG_VERSION_LEN);
} }
*p = '\0'; *p = '\0';
if(name) { if(name) {
STRNCPY(name, tmp, PKG_NAME_LEN); strncpy(name, tmp, PKG_NAME_LEN);
} }
return(0); return(0);

View file

@ -197,7 +197,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
} }
if(!strlen(pkgname)) { if(!strlen(pkgname)) {
/* just use the raw filename if we can't find crap */ /* just use the raw filename if we can't find crap */
STRNCPY(pkgname, fn, PKG_NAME_LEN+1); strncpy(pkgname, fn, PKG_NAME_LEN);
} }
_alpm_log(PM_LOG_DEBUG, _("using '%s' for download progress"), pkgname); _alpm_log(PM_LOG_DEBUG, _("using '%s' for download progress"), pkgname);

View file

@ -266,7 +266,7 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
STRNCPY(targline, name, PKG_FULLNAME_LEN); strncpy(targline, name, PKG_FULLNAME_LEN);
targ = strchr(targline, '/'); targ = strchr(targline, '/');
if(targ) { if(targ) {
*targ = '\0'; *targ = '\0';

View file

@ -449,7 +449,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
/* chop off the root so we can find the tmpdir in the chroot */ /* chop off the root so we can find the tmpdir in the chroot */
scriptpath = scriptfn + strlen(root) - 1; scriptpath = scriptfn + strlen(root) - 1;
} else { } else {
STRNCPY(scriptfn, installfn, PATH_MAX); strncpy(scriptfn, installfn, PATH_MAX);
/* chop off the root so we can find the tmpdir in the chroot */ /* chop off the root so we can find the tmpdir in the chroot */
scriptpath = scriptfn + strlen(root) - 1; scriptpath = scriptfn + strlen(root) - 1;
} }

View file

@ -34,11 +34,6 @@
#define ASSERT(cond, action) do { if(!(cond)) { action; } } while(0) #define ASSERT(cond, action) do { if(!(cond)) { action; } } while(0)
#define STRNCPY(s1, s2, len) do { \
strncpy(s1, s2, (len)-1); \
s1[(len)-1] = 0; \
} while(0)
#define ARCHIVE_EXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_TIME #define ARCHIVE_EXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_TIME
/* define _() as shortcut for gettext() */ /* define _() as shortcut for gettext() */
@ -62,6 +57,7 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn);
int _alpm_rmrf(const char *path); int _alpm_rmrf(const char *path);
int _alpm_logaction(unsigned short usesyslog, FILE *f, const char *str); int _alpm_logaction(unsigned short usesyslog, FILE *f, const char *str);
int _alpm_ldconfig(const char *root); int _alpm_ldconfig(const char *root);
/* TODO wtf? this can't be right */
#ifdef _ALPM_TRANS_H #ifdef _ALPM_TRANS_H
int _alpm_runscriptlet(const char *root, const char *installfn, int _alpm_runscriptlet(const char *root, const char *installfn,
const char *script, const char *ver, const char *script, const char *ver,