This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
$! and $1 are PVMG(), but their content is undefined when peeking
[perl5.git] / mint / pwd.c
1 /* pwd.c - replacement for broken pwd command.
2  * Copyright 1997 Guido Flohr, <gufl0000@stud.uni-sb.de>.
3  * Do with it as you please.
4  */
5 #include <stdio.h>
6 #include <limits.h>
7 #include <unistd.h>
8 #include <string.h>
9 #include <errno.h>
10
11 #if defined(__STDC__) || defined(__cplusplus)
12 int main (int argc, char* argv[])
13 #else
14 int main (argc, argv)
15         int argc;
16         char* argv[];
17 #endif
18 {
19         char path_buf[PATH_MAX + 1];
20         
21         if (argc > 1) {
22                 int i;
23                 
24                 fflush (stdout);
25                 fputs (argv[0], stderr);
26                 fputs (": ignoring garbage arguments\n", stderr);
27         }
28         
29         if (!getcwd (path_buf, PATH_MAX + 1)) {
30                 fflush (stdout);
31                 /* Save space, memory and the whales, avoid fprintf.  */
32                 fputs (argv[0], stderr);
33                 fputs (": can\'t get current working directory: ", stderr);
34                 fputs (strerror (errno), stderr);
35                 fputc ('\n', stderr);
36                 return 1;
37         }
38         if (puts (path_buf) < 0) {
39                 return 1;
40         }
41         return 0;
42 }
43 /* End of pwd.c.  */