* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static const char copyright[] =
+__used static const char copyright[] =
"@(#) Copyright (c) 1988, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
void a_gid(const char *);
void a_uid(const char *);
void chownerr(const char *);
-u_long id(const char *, const char *);
+static uid_t id(const char *, const char *);
void usage(void);
uid_t uid;
gid_t gid;
int ischown;
+#ifdef __APPLE__
+int isnumeric = 0;
+#endif
const char *gname;
int
{
FTS *ftsp;
FTSENT *p;
- int Hflag, Lflag, Rflag, fflag, hflag, vflag;
+ int Hflag, Lflag, Pflag, Rflag, fflag, hflag, vflag;
int ch, fts_options, rval;
char *cp;
int unix2003_compat = 0;
cp = (cp != NULL) ? cp + 1 : argv[0];
ischown = (strcmp(cp, "chown") == 0);
- Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
+ Hflag = Lflag = Pflag = Rflag = fflag = hflag = vflag = 0;
+#ifdef __APPLE__
+ while ((ch = getopt(argc, argv, "HLPRfhnv")) != -1)
+#else
while ((ch = getopt(argc, argv, "HLPRfhv")) != -1)
+#endif
switch (ch) {
case 'H':
Hflag = 1;
- Lflag = 0;
+ Lflag = Pflag = 0;
break;
case 'L':
Lflag = 1;
- Hflag = 0;
+ Hflag = Pflag = 0;
break;
case 'P':
+ Pflag = 1;
Hflag = Lflag = 0;
break;
case 'R':
case 'h':
hflag = 1;
break;
+#ifdef __APPLE__
+ case 'n':
+ isnumeric = 1;
+ break;
+#endif
case 'v':
vflag = 1;
break;
if (argc < 2)
usage();
+ if (!Rflag && (Hflag || Lflag || Pflag))
+ warnx("options -H, -L, -P only useful with -R");
if (Rflag) {
fts_options = FTS_PHYSICAL;
if (*s == '\0') /* Argument was "uid[:.]". */
return;
gname = s;
+#ifdef __APPLE__
+ gid = (!isnumeric && ((gr = getgrnam(s)) != NULL)) ? gr->gr_gid : id(s, "group");
+#else
gid = ((gr = getgrnam(s)) != NULL) ? gr->gr_gid : id(s, "group");
+#endif
}
void
if (*s == '\0') /* Argument was "[:.]gid". */
return;
+#ifdef __APPLE__
+ uid = (!isnumeric && ((pw = getpwnam(s)) != NULL)) ? pw->pw_uid : id(s, "user");
+#else
uid = ((pw = getpwnam(s)) != NULL) ? pw->pw_uid : id(s, "user");
+#endif
}
-u_long
+static uid_t
id(const char *name, const char *type)
{
- u_long val;
+ unsigned long val;
char *ep;
- /*
- * XXX
- * We know that uid_t's and gid_t's are unsigned longs.
- */
errno = 0;
val = strtoul(name, &ep, 10);
- if (errno)
- err(1, "%s", name);
- if (*ep != '\0')
+ if (errno || *ep != '\0' || val > UID_MAX)
errx(1, "%s: illegal %s name", name, type);
- return (val);
+ return (uid_t)val;
}
void
if (ischown)
(void)fprintf(stderr, "%s\n%s\n",
+#ifdef __APPLE__
+ "usage: chown [-fhnv] [-R [-H | -L | -P]] owner[:group]"
+ " file ...",
+ " chown [-fhnv] [-R [-H | -L | -P]] :group file ...");
+#else
"usage: chown [-fhv] [-R [-H | -L | -P]] owner[:group]"
" file ...",
" chown [-fhv] [-R [-H | -L | -P]] :group file ...");
+#endif
else
(void)fprintf(stderr, "%s\n",
+#ifdef __APPLE__
+ "usage: chgrp [-fhnv] [-R [-H | -L | -P]] group file ...");
+#else
"usage: chgrp [-fhv] [-R [-H | -L | -P]] group file ...");
+#endif
exit(1);
}