Use errc/warnc to simplify code.
authorguenther <guenther@openbsd.org>
Wed, 21 May 2014 06:23:01 +0000 (06:23 +0000)
committerguenther <guenther@openbsd.org>
Wed, 21 May 2014 06:23:01 +0000 (06:23 +0000)
ok jca@ krw@

bin/chmod/chmod.c
bin/cp/cp.c
bin/dd/args.c
bin/mv/mv.c
bin/rm/rm.c
sbin/mount_nfs/mount_nfs.c
sbin/newfs_ext2fs/newfs_ext2fs.c

index 64a9daf..203d2a3 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: chmod.c,v 1.29 2014/03/16 18:38:30 guenther Exp $     */
+/*     $OpenBSD: chmod.c,v 1.30 2014/05/21 06:23:01 guenther Exp $     */
 /*     $NetBSD: chmod.c,v 1.12 1995/03/21 09:02:09 cgd Exp $   */
 
 /*
@@ -212,7 +212,7 @@ done:
                        else
                                continue;
                case FTS_DNR:                   /* Warn, chmod, continue. */
-                       warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
+                       warnc(p->fts_errno, "%s", p->fts_path);
                        rval = 1;
                        break;
                case FTS_DP:                    /* Already changed at FTS_D. */
@@ -222,7 +222,7 @@ done:
                                break;
                case FTS_ERR:                   /* Warn, continue. */
                case FTS_NS:
-                       warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
+                       warnc(p->fts_errno, "%s", p->fts_path);
                        rval = 1;
                        continue;
                case FTS_SL:                    /* Ignore. */
index 27ad524..436e4eb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cp.c,v 1.35 2012/08/28 06:02:58 otto Exp $    */
+/*     $OpenBSD: cp.c,v 1.36 2014/05/21 06:23:02 guenther Exp $        */
 /*     $NetBSD: cp.c,v 1.14 1995/09/07 06:14:51 jtc Exp $      */
 
 /*
@@ -409,10 +409,8 @@ copy(char *argv[], enum op type, int fts_options)
                                if (mkdir(to.p_path,
                                    curr->fts_statp->st_mode | S_IRWXU) < 0)
                                        err(1, "%s", to.p_path);
-                       } else if (!S_ISDIR(to_stat.st_mode)) {
-                               errno = ENOTDIR;
-                               err(1, "%s", to.p_path);
-                       }
+                       } else if (!S_ISDIR(to_stat.st_mode))
+                               errc(1, ENOTDIR, "%s", to.p_path);
                        break;
                case S_IFBLK:
                case S_IFCHR:
@@ -432,7 +430,7 @@ copy(char *argv[], enum op type, int fts_options)
                                        rval = 1;
                        break;
                case S_IFSOCK:
-                       warnx("%s: %s", curr->fts_path, strerror(EOPNOTSUPP));
+                       warnc(EOPNOTSUPP, "%s", curr->fts_path);
                        break;
                default:
                        if (copy_file(curr, fts_dne(curr)))
index 827337a..fb0f017 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: args.c,v 1.24 2014/03/27 15:32:13 tedu Exp $  */
+/*     $OpenBSD: args.c,v 1.25 2014/05/21 06:23:02 guenther Exp $      */
 /*     $NetBSD: args.c,v 1.7 1996/03/01 01:18:58 jtc Exp $     */
 
 /*-
@@ -383,7 +383,7 @@ get_bsz(char *val)
        }
        return (num);
 erange:
-       errx(1, "%s: %s", oper, strerror(ERANGE));
+       errc(1, ERANGE, "%s", oper);
 }
 
 /*
@@ -462,5 +462,5 @@ get_off(char *val)
        }
        return (num);
 erange:
-       errx(1, "%s: %s", oper, strerror(ERANGE));
+       errc(1, ERANGE, "%s", oper);
 }
index 979797d..23c49fb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: mv.c,v 1.35 2009/10/27 23:59:22 deraadt Exp $ */
+/*     $OpenBSD: mv.c,v 1.36 2014/05/21 06:23:02 guenther Exp $        */
 /*     $NetBSD: mv.c,v 1.9 1995/03/21 09:06:52 cgd Exp $       */
 
 /*
@@ -300,13 +300,13 @@ err:              if (unlink(to))
        (void)close(from_fd);
 
        if (badchown) {
-               errno = serrno;
                if ((sbp->st_mode & (S_ISUID|S_ISGID)))  {
-                       warn("%s: set owner/group; not setting setuid/setgid",
+                       warnc(serrno,
+                           "%s: set owner/group; not setting setuid/setgid",
                            to);
                        sbp->st_mode &= ~(S_ISUID|S_ISGID);
                } else if (!fflg)
-                       warn("%s: set owner/group", to);
+                       warnc(serrno, "%s: set owner/group", to);
        }
        if (fchmod(to_fd, sbp->st_mode))
                warn("%s: set mode", to);
index bc08516..ed43f02 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rm.c,v 1.28 2013/04/23 18:41:08 deraadt Exp $ */
+/*     $OpenBSD: rm.c,v 1.29 2014/05/21 06:23:02 guenther Exp $        */
 /*     $NetBSD: rm.c,v 1.19 1995/09/07 06:48:50 jtc Exp $      */
 
 /*-
@@ -152,7 +152,7 @@ rm_tree(char **argv)
                        }
                        continue;
                case FTS_ERR:
-                       errx(1, "%s: %s", p->fts_path, strerror(p->fts_errno));
+                       errc(1, p->fts_errno, "%s", p->fts_path);
                case FTS_NS:
                        /*
                         * FTS_NS: assume that if can't stat the file, it
index 33c0c69..74a10d6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: mount_nfs.c,v 1.50 2012/05/29 20:04:59 jasper Exp $   */
+/*     $OpenBSD: mount_nfs.c,v 1.51 2014/05/21 06:23:01 guenther Exp $ */
 /*     $NetBSD: mount_nfs.c,v 1.12.4.1 1996/05/25 22:48:05 fvdl Exp $  */
 
 /*
@@ -505,8 +505,7 @@ tryagain:
        if (nfhret.stat) {
                if (opflags & ISBGRND)
                        exit(1);
-               errno = nfhret.stat;
-               warnx("can't access %s: %s", spec, strerror(nfhret.stat));
+               warnc(nfhret.stat, "can't access %s", spec);
                return (0);
        }
        saddr.sin_port = htons(tport);
index ba3e8e3..55e2eb5 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: newfs_ext2fs.c,v 1.11 2014/04/22 00:23:35 guenther Exp $ */
+/* $OpenBSD: newfs_ext2fs.c,v 1.12 2014/05/21 06:23:01 guenther Exp $ */
 /*     $NetBSD: newfs_ext2fs.c,v 1.8 2009/03/02 10:38:13 tsutsui Exp $ */
 
 /*
@@ -511,7 +511,7 @@ getpartition(int fsi, const char *special, char *argv[], struct disklabel **dl)
        struct partition *pp;
 
        if (fstat(fsi, &st) < 0)
-               errx(EXIT_FAILURE, "%s: %s", special, strerror(errno));
+               err(EXIT_FAILURE, "%s", special);
        if (S_ISBLK(st.st_mode))
                errx(EXIT_FAILURE, "%s: block device", special);
        if (!S_ISCHR(st.st_mode))