X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fshare%2Fgrabbag%2Ffile.c;h=dd2880cb3f5f204f73aa23bb1152c72f4740a0ab;hb=7dc5e3a8ff3f1b348580f48cccf4d2fd24d6384e;hp=9c15788858c5522e16257465680b09dadcf942ad;hpb=1568b1f7854e594da16d86bbb7bcf280f01aa18a;p=platform%2Fupstream%2Fflac.git diff --git a/src/share/grabbag/file.c b/src/share/grabbag/file.c index 9c15788..dd2880c 100644 --- a/src/share/grabbag/file.c +++ b/src/share/grabbag/file.c @@ -1,19 +1,19 @@ /* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson + * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009 Josh Coalson * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #if HAVE_CONFIG_H @@ -40,27 +40,32 @@ #include #include #include /* for strrchr() */ +#if defined _WIN32 && !defined __CYGWIN__ +// for GetFileInformationByHandle() etc +#include +#include +#endif #include "share/grabbag.h" void grabbag__file_copy_metadata(const char *srcpath, const char *destpath) { - struct stat srcstat; + struct flac_stat_s srcstat; struct utimbuf srctime; - if(0 == stat(srcpath, &srcstat)) { + if(0 == flac_stat(srcpath, &srcstat)) { srctime.actime = srcstat.st_atime; srctime.modtime = srcstat.st_mtime; - (void)chmod(destpath, srcstat.st_mode); - (void)utime(destpath, &srctime); + (void)flac_chmod(destpath, srcstat.st_mode); + (void)flac_utime(destpath, &srctime); } } -off_t grabbag__file_get_filesize(const char *srcpath) +FLAC__off_t grabbag__file_get_filesize(const char *srcpath) { - struct stat srcstat; + struct flac_stat_s srcstat; - if(0 == stat(srcpath, &srcstat)) + if(0 == flac_stat(srcpath, &srcstat)) return srcstat.st_size; else return -1; @@ -81,9 +86,9 @@ const char *grabbag__file_get_basename(const char *srcpath) FLAC__bool grabbag__file_change_stats(const char *filename, FLAC__bool read_only) { - struct stat stats; + struct flac_stat_s stats; - if(0 == stat(filename, &stats)) { + if(0 == flac_stat(filename, &stats)) { #if !defined _MSC_VER && !defined __MINGW32__ if(read_only) { stats.st_mode &= ~S_IWUSR; @@ -99,7 +104,7 @@ FLAC__bool grabbag__file_change_stats(const char *filename, FLAC__bool read_only else stats.st_mode |= S_IWRITE; #endif - if(0 != chmod(filename, stats.st_mode)) + if(0 != flac_chmod(filename, stats.st_mode)) return false; } else @@ -111,19 +116,46 @@ FLAC__bool grabbag__file_change_stats(const char *filename, FLAC__bool read_only FLAC__bool grabbag__file_are_same(const char *f1, const char *f2) { #if defined _MSC_VER || defined __MINGW32__ - return f1 && f2 && 0 == strcmp(f1, f2); /*@@@@@@ need better method than strcmp */ + /* see + * http://www.hydrogenaudio.org/forums/index.php?showtopic=49439&pid=444300&st=0 + * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileinformationbyhandle.asp + * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/by_handle_file_information_str.asp + * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp + * apparently both the files have to be open at the same time for the comparison to work + */ + FLAC__bool same = false; + BY_HANDLE_FILE_INFORMATION info1, info2; + HANDLE h1, h2; + BOOL ok = 1; + h1 = CreateFile(f1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + h2 = CreateFile(f2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if(h1 == INVALID_HANDLE_VALUE || h2 == INVALID_HANDLE_VALUE) + ok = 0; + ok &= GetFileInformationByHandle(h1, &info1); + ok &= GetFileInformationByHandle(h2, &info2); + if(ok) + same = + info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber && + info1.nFileIndexHigh == info2.nFileIndexHigh && + info1.nFileIndexLow == info2.nFileIndexLow + ; + if(h1 != INVALID_HANDLE_VALUE) + CloseHandle(h1); + if(h2 != INVALID_HANDLE_VALUE) + CloseHandle(h2); + return same; #else - struct stat s1, s2; - return f1 && f2 && stat(f1, &s1) == 0 && stat(f2, &s2) == 0 && s1.st_ino == s2.st_ino && s1.st_dev == s2.st_dev; + struct flac_stat_s s1, s2; + return f1 && f2 && flac_stat(f1, &s1) == 0 && flac_stat(f2, &s2) == 0 && s1.st_ino == s2.st_ino && s1.st_dev == s2.st_dev; #endif } FLAC__bool grabbag__file_remove_file(const char *filename) { - return grabbag__file_change_stats(filename, /*read_only=*/false) && 0 == unlink(filename); + return grabbag__file_change_stats(filename, /*read_only=*/false) && 0 == flac_unlink(filename); } -FILE *grabbag__file_get_binary_stdin() +FILE *grabbag__file_get_binary_stdin(void) { /* if something breaks here it is probably due to the presence or * absence of an underscore before the identifiers 'setmode', @@ -141,7 +173,7 @@ FILE *grabbag__file_get_binary_stdin() return stdin; } -FILE *grabbag__file_get_binary_stdout() +FILE *grabbag__file_get_binary_stdout(void) { /* if something breaks here it is probably due to the presence or * absence of an underscore before the identifiers 'setmode',