add pwd, thanks stateless

This commit is contained in:
Connor Lane Smith 2011-05-23 20:15:19 +01:00
parent 474ee643ed
commit 687e5411ee
5 changed files with 33 additions and 2 deletions

View File

@ -2,6 +2,7 @@ MIT/X Consortium License
© 2011 Connor Lane Smith <cls@lubutu.com> © 2011 Connor Lane Smith <cls@lubutu.com>
© 2011 Kamil Cholewiński <harry666t@gmail.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 Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), copy of this software and associated documentation files (the "Software"),

View File

@ -1,6 +1,6 @@
include config.mk 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 OBJ = $(SRC:.c=.o) util.o
BIN = $(SRC:.c=) BIN = $(SRC:.c=)
MAN = $(SRC:.c=.1) MAN = $(SRC:.c=.1)

View File

@ -7,7 +7,7 @@ basename \- strip directory from filename
.RI [ suffix ] .RI [ suffix ]
.SH DESCRIPTION .SH DESCRIPTION
.B basename .B basename
prints to stdout the prints the
.I string .I string
with any leading directory components, and the with any leading directory components, and the
.IR suffix , .IR suffix ,

8
pwd.1 Normal file
View File

@ -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.

22
pwd.c Normal file
View File

@ -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;
}