From owner-svn-soc-all@FreeBSD.ORG Mon Jul 8 16:30:22 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 4CFF8E04 for ; Mon, 8 Jul 2013 16:30:22 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 3D1591BA6 for ; Mon, 8 Jul 2013 16:30:22 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r68GUMnS024245 for ; Mon, 8 Jul 2013 16:30:22 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r68GUM5f024235 for svn-soc-all@FreeBSD.org; Mon, 8 Jul 2013 16:30:22 GMT (envelope-from dpl@FreeBSD.org) Date: Mon, 8 Jul 2013 16:30:22 GMT Message-Id: <201307081630.r68GUM5f024235@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r254421 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jul 2013 16:30:22 -0000 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 ); } }