realpath.c (08995e292e9870964bce2c1a8c008635b769c2c8) realpath.c (7a416f3e7dae7230b01fb5e4bd30d83f9c925d34)
1/*-
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 30 unchanged lines hidden (view full) ---

39
40static void usage(void) __dead2;
41
42int
43main(int argc, char *argv[])
44{
45 char buf[PATH_MAX];
46 char *p;
1/*-
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 30 unchanged lines hidden (view full) ---

39
40static void usage(void) __dead2;
41
42int
43main(int argc, char *argv[])
44{
45 char buf[PATH_MAX];
46 char *p;
47 int ch, i, qflag, rval;
47 const char *path;
48 int ch, qflag, rval;
48
49 qflag = 0;
50 while ((ch = getopt(argc, argv, "q")) != -1) {
51 switch (ch) {
52 case 'q':
53 qflag = 1;
54 break;
55 case '?':
56 default:
57 usage();
58 }
59 }
60 argc -= optind;
61 argv += optind;
49
50 qflag = 0;
51 while ((ch = getopt(argc, argv, "q")) != -1) {
52 switch (ch) {
53 case 'q':
54 qflag = 1;
55 break;
56 case '?':
57 default:
58 usage();
59 }
60 }
61 argc -= optind;
62 argv += optind;
62 if (argc < 1)
63 usage();
63 path = *argv != NULL ? *argv++ : ".";
64 rval = 0;
64 rval = 0;
65 for (i = 0; i < argc; i++) {
66 if ((p = realpath(argv[i], buf)) == NULL) {
65 do {
66 if ((p = realpath(path, buf)) == NULL) {
67 if (!qflag)
67 if (!qflag)
68 warn("%s", argv[i]);
68 warn("%s", path);
69 rval = 1;
70 } else
71 (void)printf("%s\n", p);
69 rval = 1;
70 } else
71 (void)printf("%s\n", p);
72 }
72 } while ((path = *argv++) != NULL);
73 exit(rval);
74}
75
76static void
77usage(void)
78{
79
73 exit(rval);
74}
75
76static void
77usage(void)
78{
79
80 (void)fprintf(stderr, "usage: realpath [-q] path [...]\n");
80 (void)fprintf(stderr, "usage: realpath [-q] [path ...]\n");
81 exit(1);
82}
81 exit(1);
82}