Date: Tue, 9 Jul 2013 07:08:54 GMT From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r254449 - soc2013/dpl/head/contrib/bzip2 Message-ID: <201307090708.r6978sgl091684@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dpl Date: Tue Jul 9 07:08:54 2013 New Revision: 254449 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254449 Log: Final touches with bzip2. It now works on any directory. Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Tue Jul 9 06:51:41 2013 (r254448) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Tue Jul 9 07:08:54 2013 (r254449) @@ -92,6 +92,7 @@ # include <osreldate.h> # if __FreeBSD_version >= 900041 # define CAPSICUM +# include <libgen.h> # include <sys/capability.h> # include <sys/wait.h> # include <sys/un.h> @@ -225,11 +226,9 @@ #define IN_FILENO fileno(inStr) #define OUT_FILENO fileno(outStr) void limitfd(int); -const Char * getdir(Char* file); -const Char * getfilename(Char* file); FILE *inStr; FILE *outStr; -int cwd; /* Where is the file (fd) */ +int cwd; /* Dir where is the file */ #endif static void panic ( const Char* ) NORETURN; @@ -687,46 +686,6 @@ exit(exitValue); } } - - -/*---------------------------------------------*/ -const Char * -getdir(Char *file) -{ - Char * slashPos; - Char * ret; - - slashPos = strrchr(file, (int)'/'); - if ( slashPos == 0 ) - return( "." ); - if ( (ret = strndup( file, (slashPos - file + 1)) ) == NULL){ - setExit(1); - exit(exitValue); - } - return(ret); - -} - - -/*---------------------------------------------*/ -const Char * -getfilename(Char *file) -{ - Char * slashPos; - Char * ret; - int slashIndex; - - slashPos = strrchr(file, (int)'/'); - if ( slashPos == 0 ) - return( file ); - slashIndex = slashPos - file; - if ( (ret = strndup( slashPos + 1, (strlen(file) - slashIndex) )) == NULL){ - setExit(1); - exit(exitValue); - } - return(ret); - -} #endif /*---------------------------------------------*/ @@ -781,7 +740,7 @@ progName, outName ); if (outputHandleJustInCase != NULL) fclose ( outputHandleJustInCase ); - retVal = unlinkat ( cwd, getfilename(inName), 0 ); + retVal = unlinkat ( cwd, basename(inName), 0 ); if (retVal != 0) fprintf ( stderr, "%s: WARNING: deletion of output file " @@ -1287,7 +1246,7 @@ } if ( srcMode == SM_F2F && fileExists ( outName ) ) { if (forceOverwrite) { - unlinkat ( cwd, getfilename(inName), 0 ); + unlinkat ( cwd, basename(inName), 0 ); } else { fprintf ( stderr, "%s: Output file %s already exists.\n", progName, outName ); @@ -1403,7 +1362,7 @@ applySavedTimeInfoToOutputFile ( OUT_FILENO ); deleteOutputOnInterrupt = False; if ( !keepInputFiles ) { - IntNative retVal = unlinkat ( cwd, getfilename(inName), 0 ); + IntNative retVal = unlinkat ( cwd, basename(inName), 0 ); ERROR_IF_NOT_ZERO ( retVal ); } } @@ -1500,7 +1459,7 @@ } if ( srcMode == SM_F2F && fileExists ( outName ) ) { if (forceOverwrite) { - unlinkat ( cwd, getfilename(inName), 0 ); + unlinkat ( cwd, basename(inName), 0 ); } else { fprintf ( stderr, "%s: Output file %s already exists.\n", progName, outName ); @@ -1616,7 +1575,7 @@ applySavedTimeInfoToOutputFile ( OUT_FILENO ); deleteOutputOnInterrupt = False; if ( !keepInputFiles ) { - IntNative retVal = unlinkat ( cwd, getfilename(inName), 0 ); + IntNative retVal = unlinkat ( cwd, basename(inName), 0 ); ERROR_IF_NOT_ZERO ( retVal ); } } @@ -1624,7 +1583,7 @@ unzFailsExist = True; deleteOutputOnInterrupt = False; if ( srcMode == SM_F2F ) { - IntNative retVal = unlinkat ( cwd, getfilename(inName), 0 ); + IntNative retVal = unlinkat ( cwd, basename(inName), 0 ); ERROR_IF_NOT_ZERO ( retVal ); } } @@ -2112,7 +2071,7 @@ if (aa->name[0] == '-' && decode) continue; numFilesProcessed++; # ifdef CAPSICUM - cwd = open ( getdir(aa->name) , O_DIRECTORY ); + cwd = open ( dirname(aa->name) , O_DIRECTORY ); # endif compress ( aa->name ); } @@ -2131,7 +2090,7 @@ if (aa->name[0] == '-' && decode) continue; numFilesProcessed++; # ifdef CAPSICUM - cwd = open ( getdir(aa->name) , 0 ); + cwd = open ( dirname(aa->name) , 0 ); # endif uncompress ( aa->name ); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307090708.r6978sgl091684>