[PATCH] replace bcopy,bzero,index and rindex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <impulze@xxxxxxxxxxx>
---
 fdisk/cfdisk.c            |    2 +-
 fdisk/fdiskbsdlabel.c     |   13 +++++++------
 fdisk/sfdisk.c            |   10 +++++-----
 login-utils/login.c       |    6 +++---
 login-utils/shutdown.c    |    2 +-
 login-utils/ttymsg.c      |    2 +-
 login-utils/vipw.c        |    4 ++--
 login-utils/wall.c        |    2 +-
 misc-utils/logger.c       |    2 +-
 misc-utils/whereis.c      |    4 ++--
 mount/mount.c             |    4 ++--
 mount/mount_mntent.c      |    4 ++--
 mount/sundries.c          |    2 +-
 partx/partx.c             |    2 +-
 shlibs/blkid/src/config.c |    4 ++--
 text-utils/colcrt.c       |    4 ++--
 text-utils/display.c      |    2 +-
 text-utils/parse.c        |    8 ++++----
 text-utils/ul.c           |    2 +-
 19 files changed, 40 insertions(+), 39 deletions(-)

--
Mierswa, Daniel

If you still don't like it, that's ok: that's why I'm boss. I simply know better than you do.
               --- Linus Torvalds, comp.os.linux.advocacy, 1996/07/22
diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c
index fc0357d..1846e11 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 377b64e..d5243b9 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 da779aa..8fae5bb 100644
--- a/fdisk/sfdisk.c
+++ b/fdisk/sfdisk.c
@@ -40,7 +40,7 @@
 #include <unistd.h>		/* read, write */
 #include <fcntl.h>		/* O_RDWR */
 #include <errno.h>		/* ERANGE */
-#include <string.h>		/* index() */
+#include <string.h>		/* strchr(), strrchr() */
 #include <ctype.h>
 #include <getopt.h>
 #include <sys/ioctl.h>
@@ -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 7328ede..486b30b 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 <michael@xxxxxxxxxxxxxxxxxxxx>
 	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 f798e58..58600b9 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 24b74bc..92282c1 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 5f44721..b3972f3 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 42856ae..7b5f671 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 72a8f85..95050a1 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 71ee683..931ff77 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 ef478c7..e8cb549 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 e6e64bb..f2623fd 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 3980f81..658eec5 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 8650742..25485ff 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 9091736..fcc7b6f 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 891fd86..6f79665 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 3d4bdcd..91857c2 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 d7a3020..8164c60 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 76c0a97..a1491b8 100644
--- a/text-utils/ul.c
+++ b/text-utils/ul.c
@@ -42,7 +42,7 @@
 
 #include <stdio.h>
 #include <unistd.h>		/* for getopt(), isatty() */
-#include <string.h>		/* for bzero(), strcpy() */
+#include <string.h>		/* for memset(), strcpy() */
 #include <term.h>		/* for setupterm() */
 #include <stdlib.h>		/* for getenv() */
 #include <limits.h>		/* for INT_MAX */


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux