Lines 51-56
Link Here
|
51 |
#include <grp.h> |
51 |
#include <grp.h> |
52 |
#include <libgen.h> |
52 |
#include <libgen.h> |
53 |
#include <pwd.h> |
53 |
#include <pwd.h> |
|
|
54 |
#include <signal.h> |
54 |
#include <stdint.h> |
55 |
#include <stdint.h> |
55 |
#include <stdio.h> |
56 |
#include <stdio.h> |
56 |
#include <stdlib.h> |
57 |
#include <stdlib.h> |
Lines 62-73
Link Here
|
62 |
static void chownerr(const char *); |
63 |
static void chownerr(const char *); |
63 |
static uid_t id(const char *, const char *); |
64 |
static uid_t id(const char *, const char *); |
64 |
static void usage(void); |
65 |
static void usage(void); |
|
|
66 |
static void print_info(const FTSENT *, int); |
65 |
|
67 |
|
66 |
static uid_t uid; |
68 |
static uid_t uid; |
67 |
static gid_t gid; |
69 |
static gid_t gid; |
68 |
static int ischown; |
70 |
static int ischown; |
69 |
static const char *gname; |
71 |
static const char *gname; |
|
|
72 |
static volatile sig_atomic_t siginfo; |
70 |
|
73 |
|
|
|
74 |
static void |
75 |
siginfo_handler(int sig __unused) |
76 |
{ |
77 |
|
78 |
siginfo = 1; |
79 |
} |
80 |
|
71 |
int |
81 |
int |
72 |
main(int argc, char **argv) |
82 |
main(int argc, char **argv) |
73 |
{ |
83 |
{ |
Lines 118-123
Link Here
|
118 |
if (argc < 2) |
128 |
if (argc < 2) |
119 |
usage(); |
129 |
usage(); |
120 |
|
130 |
|
|
|
131 |
(void)signal(SIGINFO, siginfo_handler); |
132 |
|
121 |
if (Rflag) { |
133 |
if (Rflag) { |
122 |
fts_options = FTS_PHYSICAL; |
134 |
fts_options = FTS_PHYSICAL; |
123 |
if (hflag && (Hflag || Lflag)) |
135 |
if (hflag && (Hflag || Lflag)) |
Lines 184-189
Link Here
|
184 |
default: |
196 |
default: |
185 |
break; |
197 |
break; |
186 |
} |
198 |
} |
|
|
199 |
if (siginfo) { |
200 |
print_info(p, 2); |
201 |
siginfo = 0; |
202 |
} |
187 |
if ((uid == (uid_t)-1 || uid == p->fts_statp->st_uid) && |
203 |
if ((uid == (uid_t)-1 || uid == p->fts_statp->st_uid) && |
188 |
(gid == (gid_t)-1 || gid == p->fts_statp->st_gid)) |
204 |
(gid == (gid_t)-1 || gid == p->fts_statp->st_gid)) |
189 |
continue; |
205 |
continue; |
Lines 193-227
Link Here
|
193 |
rval = 1; |
209 |
rval = 1; |
194 |
} |
210 |
} |
195 |
} else { |
211 |
} else { |
196 |
if (vflag) { |
212 |
if (vflag) |
197 |
printf("%s", p->fts_path); |
213 |
print_info(p, vflag); |
198 |
if (vflag > 1) { |
|
|
199 |
if (ischown) { |
200 |
printf(": %ju:%ju -> %ju:%ju", |
201 |
(uintmax_t) |
202 |
p->fts_statp->st_uid, |
203 |
(uintmax_t) |
204 |
p->fts_statp->st_gid, |
205 |
(uid == (uid_t)-1) ? |
206 |
(uintmax_t) |
207 |
p->fts_statp->st_uid : |
208 |
(uintmax_t)uid, |
209 |
(gid == (gid_t)-1) ? |
210 |
(uintmax_t) |
211 |
p->fts_statp->st_gid : |
212 |
(uintmax_t)gid); |
213 |
} else { |
214 |
printf(": %ju -> %ju", |
215 |
(uintmax_t) |
216 |
p->fts_statp->st_gid, |
217 |
(gid == (gid_t)-1) ? |
218 |
(uintmax_t) |
219 |
p->fts_statp->st_gid : |
220 |
(uintmax_t)gid); |
221 |
} |
222 |
} |
223 |
printf("\n"); |
224 |
} |
225 |
} |
214 |
} |
226 |
} |
215 |
} |
227 |
if (errno) |
216 |
if (errno) |
Lines 313-315
Link Here
|
313 |
"usage: chgrp [-fhvx] [-R [-H | -L | -P]] group file ..."); |
302 |
"usage: chgrp [-fhvx] [-R [-H | -L | -P]] group file ..."); |
314 |
exit(1); |
303 |
exit(1); |
315 |
} |
304 |
} |
|
|
305 |
|
306 |
static void |
307 |
print_info(const FTSENT *p, int vflag) |
308 |
{ |
309 |
|
310 |
printf("%s", p->fts_path); |
311 |
if (vflag > 1) { |
312 |
if (ischown) { |
313 |
printf(": %ju:%ju -> %ju:%ju", |
314 |
(uintmax_t) |
315 |
p->fts_statp->st_uid, |
316 |
(uintmax_t) |
317 |
p->fts_statp->st_gid, |
318 |
(uid == (uid_t)-1) ? |
319 |
(uintmax_t) |
320 |
p->fts_statp->st_uid : |
321 |
(uintmax_t)uid, |
322 |
(gid == (gid_t)-1) ? |
323 |
(uintmax_t) |
324 |
p->fts_statp->st_gid : |
325 |
(uintmax_t)gid); |
326 |
} else { |
327 |
printf(": %ju -> %ju", |
328 |
(uintmax_t) |
329 |
p->fts_statp->st_gid, |
330 |
(gid == (gid_t)-1) ? |
331 |
(uintmax_t) |
332 |
p->fts_statp->st_gid : |
333 |
(uintmax_t)gid); |
334 |
} |
335 |
} |
336 |
printf("\n"); |
337 |
} |