pwd.c (586B)
- // Collection of Unix tools, comparable to coreutils
- // SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- // SPDX-License-Identifier: MPL-2.0
- #define _POSIX_C_SOURCE 200809L
- #include <stdio.h> /* puts, perror, printf */
- #include <unistd.h> /* getcwd() */
- int
- main(int argc, char *argv[])
- {
- char pwd[BUFSIZ];
- if(argc != 1)
- {
- fprintf(stderr, "usage: pwd\n");
- return 1;
- }
- if(getcwd(pwd, sizeof(pwd)) == NULL)
- {
- perror("pwd: getcwd");
- return 1;
- }
- else
- {
- if(puts(pwd) < 0)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- }