From 687e5411ee19d822b722e76ea257b8efb8fac429 Mon Sep 17 00:00:00 2001 From: Connor Lane Smith Date: Mon, 23 May 2011 20:15:19 +0100 Subject: [PATCH] add pwd, thanks stateless --- LICENSE | 1 + Makefile | 2 +- basename.1 | 2 +- pwd.1 | 8 ++++++++ pwd.c | 22 ++++++++++++++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 pwd.1 create mode 100644 pwd.c diff --git a/LICENSE b/LICENSE index b374d1e..03a585b 100644 --- a/LICENSE +++ b/LICENSE @@ -2,6 +2,7 @@ MIT/X Consortium License © 2011 Connor Lane Smith © 2011 Kamil Cholewiński +© 2011 stateless Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/Makefile b/Makefile index 6dc10c4..b5d52fd 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ include config.mk -SRC = basename.c cat.c date.c echo.c false.c grep.c sleep.c tee.c touch.c true.c wc.c +SRC = basename.c cat.c date.c echo.c false.c grep.c pwd.c sleep.c tee.c touch.c true.c wc.c OBJ = $(SRC:.c=.o) util.o BIN = $(SRC:.c=) MAN = $(SRC:.c=.1) diff --git a/basename.1 b/basename.1 index 8f9b14f..1dfc463 100644 --- a/basename.1 +++ b/basename.1 @@ -7,7 +7,7 @@ basename \- strip directory from filename .RI [ suffix ] .SH DESCRIPTION .B basename -prints to stdout the +prints the .I string with any leading directory components, and the .IR suffix , diff --git a/pwd.1 b/pwd.1 new file mode 100644 index 0000000..66b8ef8 --- /dev/null +++ b/pwd.1 @@ -0,0 +1,8 @@ +.TH PWD 1 sbase\-VERSION +.SH NAME +pwd \- print working directory +.SH SYNOPSIS +.B pwd +.SH DESCRIPTION +.B pwd +prints the path of the current working directory. diff --git a/pwd.c b/pwd.c new file mode 100644 index 0000000..0a27a96 --- /dev/null +++ b/pwd.c @@ -0,0 +1,22 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include "util.h" + +int +main(void) +{ + char *buf; + long size; + + if((size = pathconf(".", _PC_PATH_MAX)) < 0) + size = BUFSIZ; + if(!(buf = malloc(size))) + eprintf("malloc:"); + if(!getcwd(buf, size)) + eprintf("getcwd:"); + + puts(buf); + return EXIT_SUCCESS; +}