Discussion:
[ast-developers] [patch] patch for pwd -f $fd
ольга крыжановская
2013-11-14 22:28:26 UTC
Permalink
Glenn, David, I have attached another try, to implement pwd -f, to
print the path for a given file descriptor, based on Roland Mainz's
earlier work.

Is the patch OK?

Olga
--
, _ _ ,
{ \/`o;====- Olga Kryzhanovska -====;o`\/ }
.----'-/`-/ olga.kryzhanovska at gmail.com \-`\-'----.
`'-..-| / http://twitter.com/fleyta \ |-..-'`
/\/\ Solaris/BSD//C/C++ programmer /\/\
`--` `--`
-------------- next part --------------
diff -r -u build_i386_64bit_debug/src/cmd/ksh93/bltins/cd_pwd.c build_pwdfd/src/cmd/ksh93/bltins/cd_pwd.c
--- src/cmd/ksh93/bltins/cd_pwd.c 2013-09-02 06:43:32.000000000 +0200
+++ src/cmd/ksh93/bltins/cd_pwd.c 2013-11-14 13:55:49.384833146 +0100
@@ -305,10 +305,13 @@
register char *cp, *dir;
register Shell_t *shp = context->shp;
bool pflag = false;
- int n,fd;
+ int n,fd,ffd=-1;
NOT_USED(argc);
while((n=optget(argv,sh_optpwd))) switch(n)
{
+ case 'f':
+ ffd = opt_info.num;
+ break;
case 'L':
pflag = false;
break;
@@ -324,6 +327,17 @@
}
if(error_info.errors)
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
+
+ if (ffd != -1)
+ {
+ cp = fgetcwd(ffd, 0, 0);
+ if(!cp)
+ errormsg(SH_DICT, ERROR_system(1), e_pwd);
+ sfputr(sfstdout, cp, '\n');
+ free(cp);
+ return(0);
+ }
+
if(pflag)
{
#if SHOPT_FS_3D
diff -r -u build_i386_64bit_debug/src/cmd/ksh93/data/builtins.c build_pwdfd/src/cmd/ksh93/data/builtins.c
--- src/cmd/ksh93/data/builtins.c 2013-09-13 19:38:09.000000000 +0200
+++ src/cmd/ksh93/data/builtins.c 2013-11-14 13:56:59.341499915 +0100
@@ -1267,7 +1267,7 @@
;

const char sh_optpwd[] =
-"[-1c?\n@(#)$Id: pwd (AT&T Research) 1999-06-07 $\n]"
+"[-1c?\n@(#)$Id: pwd (AT&T Research) 2013-11-10 $\n]"
USAGE_LICENSE
"[+NAME?pwd - write working directory name]"
"[+DESCRIPTION?\bpwd\b writes an absolute pathname of the current working "
@@ -1283,11 +1283,13 @@
"[L?The absolute pathname may contains symbolic link components. This is "
"the default.]"
"[P?The absolute pathname will not contain any symbolic link components.]"
+"[f?Print the directory name for the open directory file descriptor "
+ "\afd\a. Cannot be combined with other options.]#[fd]"
"[+EXIT STATUS?]{"
"[+0?Successful completion.]"
"[+>0?An error occurred.]"
"}"
-"[+SEE ALSO?\bcd\b(1), \bgetconf\b(1)]"
+"[+SEE ALSO?\bcd\b(1), \bgetconf\b(1), \breadlink\b(1), \brealpath\b(1)]"
;

const char sh_optread[] =
Loading...