commit 687e5411ee19d822b722e76ea257b8efb8fac429
parent 474ee643edc05791771b9bf0308295b39da784e2
Author: Connor Lane Smith <cls@lubutu.com>
Date: Mon, 23 May 2011 20:15:19 +0100
add pwd, thanks stateless
Diffstat:
5 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -2,6 +2,7 @@ MIT/X Consortium License
© 2011 Connor Lane Smith <cls@lubutu.com>
© 2011 Kamil Cholewiński <harry666t@gmail.com>
+© 2011 stateless <stateless@archlinux.us>
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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,22 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#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;
+}