source: trunk/minix/commands/simple/pwd.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.1 KB
Line 
1/* pwd - print working directory Author: Norbert Schlenker */
2
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.
11 */
12
13/* Force visible Posix names */
14#ifndef _POSIX_SOURCE
15#define _POSIX_SOURCE 1
16#endif
17
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>
25
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 */
29
30_PROTOTYPE(int main, (void));
31
32static char dir[PATH_MAX + 1];
33static char *errmsg = "pwd: cannot search some directory on the path\n";
34
35int main()
36{
37 char *p;
38 size_t n;
39
40 p = getcwd(dir, PATH_MAX);
41 if (p == NULL) {
42 write(STDERR_FILENO, errmsg, strlen(errmsg));
43 exit(FAILURE);
44 }
45 n = strlen(p);
46 p[n] = '\n';
47 if (write(STDOUT_FILENO, p, n + 1) != n + 1) exit(FAILURE);
48 return(SUCCESS);
49}
Note: See TracBrowser for help on using the repository browser.