socsvn commit: r254421 - soc2013/dpl/head/contrib/bzip2
dpl at FreeBSD.org
dpl at FreeBSD.org
Mon Jul 8 16:30:22 UTC 2013
Author: dpl
Date: Mon Jul 8 16:30:21 2013
New Revision: 254421
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254421
Log:
Make bzip2 work with any file anywhere.
Modified:
soc2013/dpl/head/contrib/bzip2/bzip2.c
Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c
==============================================================================
--- soc2013/dpl/head/contrib/bzip2/bzip2.c Mon Jul 8 15:59:11 2013 (r254420)
+++ soc2013/dpl/head/contrib/bzip2/bzip2.c Mon Jul 8 16:30:21 2013 (r254421)
@@ -226,6 +226,7 @@
#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) */
@@ -698,7 +699,31 @@
slashPos = strrchr(file, (int)'/');
if ( slashPos == 0 )
return( "." );
- ret = strndup( file, (slashPos - file + 1) );
+ 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);
}
@@ -756,7 +781,7 @@
progName, outName );
if (outputHandleJustInCase != NULL)
fclose ( outputHandleJustInCase );
- retVal = unlinkat ( cwd, inName, 0 );
+ retVal = unlinkat ( cwd, getfilename(inName), 0 );
if (retVal != 0)
fprintf ( stderr,
"%s: WARNING: deletion of output file "
@@ -1262,7 +1287,7 @@
}
if ( srcMode == SM_F2F && fileExists ( outName ) ) {
if (forceOverwrite) {
- unlinkat ( cwd, inName, 0 );
+ unlinkat ( cwd, getfilename(inName), 0 );
} else {
fprintf ( stderr, "%s: Output file %s already exists.\n",
progName, outName );
@@ -1378,8 +1403,7 @@
applySavedTimeInfoToOutputFile ( OUT_FILENO );
deleteOutputOnInterrupt = False;
if ( !keepInputFiles ) {
- printf("unlinkat( %d, %s, 0);\n", cwd, inName);
- IntNative retVal = unlinkat ( cwd, inName, 0 );
+ IntNative retVal = unlinkat ( cwd, getfilename(inName), 0 );
ERROR_IF_NOT_ZERO ( retVal );
}
}
@@ -1476,7 +1500,7 @@
}
if ( srcMode == SM_F2F && fileExists ( outName ) ) {
if (forceOverwrite) {
- unlinkat ( cwd, inName, 0 );
+ unlinkat ( cwd, getfilename(inName), 0 );
} else {
fprintf ( stderr, "%s: Output file %s already exists.\n",
progName, outName );
@@ -1592,7 +1616,7 @@
applySavedTimeInfoToOutputFile ( OUT_FILENO );
deleteOutputOnInterrupt = False;
if ( !keepInputFiles ) {
- IntNative retVal = unlinkat ( cwd, inName, 0 );
+ IntNative retVal = unlinkat ( cwd, getfilename(inName), 0 );
ERROR_IF_NOT_ZERO ( retVal );
}
}
@@ -1600,7 +1624,7 @@
unzFailsExist = True;
deleteOutputOnInterrupt = False;
if ( srcMode == SM_F2F ) {
- IntNative retVal = unlinkat ( cwd, inName, 0 );
+ IntNative retVal = unlinkat ( cwd, getfilename(inName), 0 );
ERROR_IF_NOT_ZERO ( retVal );
}
}
More information about the svn-soc-all
mailing list