unstack - fix ipcvecs
[minix.git] / commands / pwd / pwd.c
blob21609f99e2f6edf7de797f965fdfe0fe0004ecb8
1 /* pwd - print working directory Author: Norbert Schlenker */
3 /*
4 * pwd - print working directory
5 * Syntax: pwd
6 * Flags: None.
7 * Author: Norbert Schlenker
8 * Copyright: None. Released to the public domain.
9 * Reference: IEEE P1003.2 Section 4.50 (draft 10)
10 * Bugs: No internationalization support; all messages are in English.
13 /* Force visible Posix names */
14 #ifndef _POSIX_SOURCE
15 #define _POSIX_SOURCE 1
16 #endif
18 /* External interfaces */
19 #include <sys/types.h>
20 #include <limits.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <stdio.h>
26 /* Magic numbers suggested or required by Posix specification */
27 #define SUCCESS 0 /* exit code in case of success */
28 #define FAILURE 1 /* or failure */
30 int main(void);
32 static char dir[PATH_MAX + 1];
33 static char *errmsg = "pwd: cannot search some directory on the path\n";
35 int main()
37 char *p;
38 size_t n;
40 p = getcwd(dir, PATH_MAX);
41 if (p == NULL) {
42 write(STDERR_FILENO, errmsg, strlen(errmsg));
43 exit(FAILURE);
45 n = strlen(p);
46 p[n] = '\n';
47 if (write(STDOUT_FILENO, p, n + 1) != n + 1) exit(FAILURE);
48 return(SUCCESS);