From: Daniel Mierswa Date: Mon, 17 Aug 2009 05:27:39 +0000 (+0200) Subject: replace bcopy,bzero,index and rindex X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0f19ccff73aa0ec5e9f3b61b932ea4a8bf4e6ed;p=util-linux replace bcopy,bzero,index and rindex Those 4 functions are marked as LEGACY in POSIX.1-2001 and removed in POSIX.1-2008. Replaced with memmove,memset,strchr and strrchr. Signed-off-by: Daniel Mierswa --- diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c index fc0357d2..1846e11c 100644 --- a/fdisk/cfdisk.c +++ b/fdisk/cfdisk.c @@ -357,7 +357,7 @@ xmalloc (size_t size) { /* Some libc's have their own basename() */ static char * my_basename(char *devname) { - char *s = rindex(devname, '/'); + char *s = strrchr(devname, '/'); return s ? s+1 : devname; } diff --git a/fdisk/fdiskbsdlabel.c b/fdisk/fdiskbsdlabel.c index 377b64ec..d5243b9e 100644 --- a/fdisk/fdiskbsdlabel.c +++ b/fdisk/fdiskbsdlabel.c @@ -538,7 +538,7 @@ xbsd_write_bootstrap (void) /* We need a backup of the disklabel (xbsd_dlabel might have changed). */ d = &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE]; - bcopy (d, &dl, sizeof (struct xbsd_disklabel)); + memmove (&dl, d, sizeof (struct xbsd_disklabel)); /* The disklabel will be overwritten by 0's from bootxx anyway */ bzero (d, sizeof (struct xbsd_disklabel)); @@ -555,7 +555,7 @@ xbsd_write_bootstrap (void) exit ( EXIT_FAILURE ); } - bcopy (&dl, d, sizeof (struct xbsd_disklabel)); + memmove (d, &dl, sizeof (struct xbsd_disklabel)); #if defined (__powerpc__) || defined (__hppa__) sector = 0; @@ -740,8 +740,9 @@ xbsd_readlabel (struct partition *p, struct xbsd_disklabel *d) if (BSD_BBSIZE != read (fd, disklabelbuffer, BSD_BBSIZE)) fatal (unable_to_read); - bcopy (&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], - d, sizeof (struct xbsd_disklabel)); + memmove (d, + &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], + sizeof (struct xbsd_disklabel)); if (d -> d_magic != BSD_DISKMAGIC || d -> d_magic2 != BSD_DISKMAGIC) return 0; @@ -776,8 +777,8 @@ xbsd_writelabel (struct partition *p, struct xbsd_disklabel *d) /* This is necessary if we want to write the bootstrap later, otherwise we'd write the old disklabel with the bootstrap. */ - bcopy (d, &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], - sizeof (struct xbsd_disklabel)); + memmove (&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], d, + sizeof (struct xbsd_disklabel)); #if defined (__alpha__) && BSD_LABELSECTOR == 0 alpha_bootblock_checksum (disklabelbuffer); diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c index da779aa8..8fae5bb5 100644 --- a/fdisk/sfdisk.c +++ b/fdisk/sfdisk.c @@ -40,7 +40,7 @@ #include /* read, write */ #include /* O_RDWR */ #include /* ERANGE */ -#include /* index() */ +#include /* strchr(), strrchr() */ #include #include #include @@ -1725,12 +1725,12 @@ read_stdin(char **fields, char *line, int fieldssize, int linesize) { eof = 1; return RD_EOF; } - if (!(lp = index(lp, '\n'))) + if (!(lp = strchr(lp, '\n'))) fatal(_("long or incomplete input line - quitting\n")); *lp = 0; /* remove comments, if any */ - if ((lp = index(line+2, '#')) != 0) + if ((lp = strchr(line+2, '#')) != 0) *lp = 0; /* recognize a few commands - to be expanded */ @@ -1740,7 +1740,7 @@ read_stdin(char **fields, char *line, int fieldssize, int linesize) { } /* dump style? - then bad input is fatal */ - if ((ip = index(line+2, ':')) != 0) { + if ((ip = strchr(line+2, ':')) != 0) { struct dumpfld *d; nxtfld: @@ -2503,7 +2503,7 @@ main(int argc, char **argv) { if (argc < 1) fatal(_("no command?\n")); - if ((progn = rindex(argv[0], '/')) == NULL) + if ((progn = strrchr(argv[0], '/')) == NULL) progn = argv[0]; else progn++; diff --git a/login-utils/login.c b/login-utils/login.c index 7328edeb..486b30bf 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -418,7 +418,7 @@ main(int argc, char **argv) */ gethostname(tbuf, sizeof(tbuf)); xstrncpy(thishost, tbuf, sizeof(thishost)); - domain = index(tbuf, '.'); + domain = strchr(tbuf, '.'); username = tty_name = hostname = NULL; fflag = hflag = pflag = 0; @@ -437,7 +437,7 @@ main(int argc, char **argv) exit(1); } hflag = 1; - if (domain && (p = index(optarg, '.')) && + if (domain && (p = strchr(optarg, '.')) && strcasecmp(p, domain) == 0) *p = 0; @@ -1251,7 +1251,7 @@ Michael Riepe childArgv[childArgc++] = buff; } else { tbuf[0] = '-'; - xstrncpy(tbuf + 1, ((p = rindex(pwd->pw_shell, '/')) ? + xstrncpy(tbuf + 1, ((p = strrchr(pwd->pw_shell, '/')) ? p + 1 : pwd->pw_shell), sizeof(tbuf)-1); diff --git a/login-utils/shutdown.c b/login-utils/shutdown.c index f798e581..58600b9d 100644 --- a/login-utils/shutdown.c +++ b/login-utils/shutdown.c @@ -281,7 +281,7 @@ main(int argc, char *argv[]) if (fgets (line, sizeof(line), fp) != NULL && strncasecmp (line, "HALT_ACTION", 11) == 0 && iswhitespace(line[11])) { - p = index(line, '\n'); + p = strchr(line, '\n'); if (p) *p = 0; /* strip final '\n' */ p = line+11; diff --git a/login-utils/ttymsg.c b/login-utils/ttymsg.c index 24b74bcb..92282c12 100644 --- a/login-utils/ttymsg.c +++ b/login-utils/ttymsg.c @@ -111,7 +111,7 @@ ttymsg(struct iovec *iov, int iovcnt, char *line, int tmout) { if (wret >= 0) { left -= wret; if (iov != localiov) { - bcopy(iov, localiov, + memmove(localiov, iov, iovcnt * sizeof(struct iovec)); iov = localiov; } diff --git a/login-utils/vipw.c b/login-utils/vipw.c index 5f447211..b3972f3b 100644 --- a/login-utils/vipw.c +++ b/login-utils/vipw.c @@ -311,8 +311,8 @@ int main(int argc, char *argv[]) { bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - bzero(tmp_file, FILENAMELEN); - progname = (rindex(argv[0], '/')) ? rindex(argv[0], '/') + 1 : argv[0]; + memset(tmp_file, '\0', FILENAMELEN); + progname = (strrchr(argv[0], '/')) ? strrchr(argv[0], '/') + 1 : argv[0]; if (!strcmp(progname, "vigr")) { program = VIGR; xstrncpy(orig_file, GROUP_FILE, sizeof(orig_file)); diff --git a/login-utils/wall.c b/login-utils/wall.c index 42856ae3..7b5f6718 100644 --- a/login-utils/wall.c +++ b/login-utils/wall.c @@ -95,7 +95,7 @@ main(int argc, char **argv) { textdomain(PACKAGE); progname = argv[0]; - p = rindex(progname, '/'); + p = strrchr(progname, '/'); if (p) progname = p+1; diff --git a/misc-utils/logger.c b/misc-utils/logger.c index 72a8f85e..95050a1b 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -196,7 +196,7 @@ main(int argc, char **argv) { } else { if (p != buf) *p++ = ' '; - bcopy(*argv++, p, len); + memmove(p, *argv++, len); *(p += len) = '\0'; } } diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c index 71ee6835..931ff77b 100644 --- a/misc-utils/whereis.c +++ b/misc-utils/whereis.c @@ -325,14 +325,14 @@ findin(char *dir, char *cp) { char dirbuf[1024]; struct stat statbuf; - dd = index(dir, '*'); + dd = strchr(dir, '*'); if (!dd) goto noglob; l = strlen(dir); if (l < sizeof(dirbuf)) { /* refuse excessively long names */ strcpy (dirbuf, dir); - d = index(dirbuf, '*'); + d = strchr(dirbuf, '*'); *d = 0; dirp = opendir(dirbuf); if (dirp == NULL) diff --git a/mount/mount.c b/mount/mount.c index ef478c79..e8cb5499 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -911,11 +911,11 @@ guess_fstype_and_mount(const char *spec, const char *node, const char **types, /* Accept a comma-separated list of types, and try them one by one */ /* A list like "nonfs,.." indicates types not to use */ - if (*types && strncmp(*types, "no", 2) && index(*types,',')) { + if (*types && strncmp(*types, "no", 2) && strchr(*types,',')) { char *t = strdup(*types); char *p; - while((p = index(t,',')) != NULL) { + while((p = strchr(t,',')) != NULL) { *p = 0; args.type = *types = t; if (do_mount (&args, special, status) == 0) diff --git a/mount/mount_mntent.c b/mount/mount_mntent.c index e6e64bbc..f2623fd5 100644 --- a/mount/mount_mntent.c +++ b/mount/mount_mntent.c @@ -157,7 +157,7 @@ my_getmntent (mntFILE *mfp) { return NULL; mfp->mntent_lineno++; - s = index (buf, '\n'); + s = strchr (buf, '\n'); if (s == NULL) { /* Missing final newline? Otherwise extremely */ /* long line - assume file was corrupted */ @@ -165,7 +165,7 @@ my_getmntent (mntFILE *mfp) { fprintf(stderr, _("[mntent]: warning: no final " "newline at the end of %s\n"), mfp->mntent_file); - s = index (buf, 0); + s = strchr (buf, 0); } else { mfp->mntent_errs = 1; goto err; diff --git a/mount/sundries.c b/mount/sundries.c index 3980f81a..658eec52 100644 --- a/mount/sundries.c +++ b/mount/sundries.c @@ -157,7 +157,7 @@ matching_type (const char *type, const char *types) { if (strncmp(p, type, len) == 0 && (p[len] == 0 || p[len] == ',')) return !no; - p = index(p,','); + p = strchr(p,','); if (!p) break; p++; diff --git a/partx/partx.c b/partx/partx.c index 86507422..25485fff 100644 --- a/partx/partx.c +++ b/partx/partx.c @@ -131,7 +131,7 @@ main(int argc, char **argv){ case 'n': p = optarg; lower = atoi(p); - p = index(p, '-'); + p = strchr(p, '-'); if (p) upper = atoi(p+1); else diff --git a/shlibs/blkid/src/config.c b/shlibs/blkid/src/config.c index 9091736b..fcc7b6f1 100644 --- a/shlibs/blkid/src/config.c +++ b/shlibs/blkid/src/config.c @@ -68,12 +68,12 @@ static int parse_next(FILE *fd, struct blkid_config *conf) do { if (fgets (buf, sizeof(buf), fd) == NULL) return feof(fd) ? 0 : -1; - s = index (buf, '\n'); + s = strchr (buf, '\n'); if (!s) { /* Missing final newline? Otherwise extremely */ /* long line - assume file was corrupted */ if (feof(fd)) - s = index (buf, '\0'); + s = strchr (buf, '\0'); else { DBG(DEBUG_CONFIG, fprintf(stderr, "libblkid: config file: missing newline at line '%s'.\n", diff --git a/text-utils/colcrt.c b/text-utils/colcrt.c index 891fd86d..6f796656 100644 --- a/text-utils/colcrt.c +++ b/text-utils/colcrt.c @@ -252,8 +252,8 @@ void pflush(int ol) } putwchar('\n'); } - bcopy(page[ol], page, (267 - ol) * 132 * sizeof(wchar_t)); - bzero(page[267- ol], ol * 132 * sizeof(wchar_t)); + memmove(page, page[ol], (267 - ol) * 132 * sizeof(wchar_t)); + memset(page[267- ol], '\0', ol * 132 * sizeof(wchar_t)); outline -= ol; outcol = 0; first = 1; diff --git a/text-utils/display.c b/text-utils/display.c index 3d4bdcd9..91857c2f 100644 --- a/text-utils/display.c +++ b/text-utils/display.c @@ -163,7 +163,7 @@ static void bpad(PR *pr) pr->cchar[0] = 's'; pr->cchar[1] = 0; for (p1 = pr->fmt; *p1 != '%'; ++p1); - for (p2 = ++p1; *p1 && index(spec, *p1); ++p1); + for (p2 = ++p1; *p1 && strchr(spec, *p1); ++p1); while ((*p2++ = *p1++) != 0) ; } diff --git a/text-utils/parse.c b/text-utils/parse.c index d7a30208..8164c601 100644 --- a/text-utils/parse.c +++ b/text-utils/parse.c @@ -64,7 +64,7 @@ void addfile(char *name) exit(1); } while (fgets(buf, sizeof(buf), fp)) { - if ((p = index(buf, '\n')) == NULL) { + if ((p = strchr(buf, '\n')) == NULL) { (void)fprintf(stderr, _("hexdump: line too long.\n")); while ((ch = getchar()) != '\n' && ch != EOF); continue; @@ -171,7 +171,7 @@ int size(FS *fs) * skip any special chars -- save precision in * case it's a %s format. */ - while (index(spec + 1, *++fmt)); + while (strchr(spec + 1, *++fmt)); if (*fmt == '.' && isdigit((unsigned char)*++fmt)) { prec = atoi(fmt); while (isdigit((unsigned char)*++fmt)); @@ -244,10 +244,10 @@ void rewrite(FS *fs) if (fu->bcnt) { sokay = USEBCNT; /* skip to conversion character */ - for (++p1; index(spec, *p1); ++p1); + for (++p1; strchr(spec, *p1); ++p1); } else { /* skip any special chars, field width */ - while (index(spec + 1, *++p1)); + while (strchr(spec + 1, *++p1)); if (*p1 == '.' && isdigit((unsigned char)*++p1)) { sokay = USEPREC; diff --git a/text-utils/ul.c b/text-utils/ul.c index 76c0a970..a1491b84 100644 --- a/text-utils/ul.c +++ b/text-utils/ul.c @@ -42,7 +42,7 @@ #include #include /* for getopt(), isatty() */ -#include /* for bzero(), strcpy() */ +#include /* for memset(), strcpy() */ #include /* for setupterm() */ #include /* for getenv() */ #include /* for INT_MAX */