1
1
/* grabbag - Convenience lib for various routines common to several tools
2
* Copyright (C) 2002,2003,2004,2005 Josh Coalson
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
2
* Copyright (C) 2002,2003,2004,2005,2006,2007 Josh Coalson
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
23
#if defined _MSC_VER || defined __MINGW32__
20
24
#include <sys/utime.h> /* for utime() */
21
25
#include <io.h> /* for chmod(), _setmode(), unlink() */
24
28
#include <sys/types.h> /* some flavors of BSD (like OS X) require this to get time_t */
25
29
#include <utime.h> /* for utime() */
31
#if defined __CYGWIN__ || defined __EMX__
28
32
#include <io.h> /* for setmode(), O_BINARY */
29
33
#include <fcntl.h> /* for _O_BINARY */
116
FLAC__bool grabbag__file_are_same(const char *f1, const char *f2)
118
#if defined _MSC_VER || defined __MINGW32__
120
* http://www.hydrogenaudio.org/forums/index.php?showtopic=49439&pid=444300&st=0
121
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileinformationbyhandle.asp
122
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/by_handle_file_information_str.asp
123
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp
124
* apparently both the files have to be open at the same time for the comparison to work
126
FLAC__bool same = false;
127
BY_HANDLE_FILE_INFORMATION info1, info2;
130
h1 = CreateFile(f1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
131
h2 = CreateFile(f2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
132
if(h1 == INVALID_HANDLE_VALUE || h2 == INVALID_HANDLE_VALUE)
134
ok &= GetFileInformationByHandle(h1, &info1);
135
ok &= GetFileInformationByHandle(h2, &info2);
138
info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber &&
139
info1.nFileIndexHigh == info2.nFileIndexHigh &&
140
info1.nFileIndexLow == info2.nFileIndexLow
142
if(h1 != INVALID_HANDLE_VALUE)
144
if(h2 != INVALID_HANDLE_VALUE)
149
return f1 && f2 && stat(f1, &s1) == 0 && stat(f2, &s2) == 0 && s1.st_ino == s2.st_ino && s1.st_dev == s2.st_dev;
107
153
FLAC__bool grabbag__file_remove_file(const char *filename)
109
155
return grabbag__file_change_stats(filename, /*read_only=*/false) && 0 == unlink(filename);
112
FILE *grabbag__file_get_binary_stdin()
158
FILE *grabbag__file_get_binary_stdin(void)
114
160
/* if something breaks here it is probably due to the presence or
115
161
* absence of an underscore before the identifiers 'setmode',
120
166
#elif defined __CYGWIN__
121
167
/* almost certainly not needed for any modern Cygwin, but let's be safe... */
122
168
setmode(_fileno(stdin), _O_BINARY);
169
#elif defined __EMX__
170
setmode(fileno(stdin), O_BINARY);
128
FILE *grabbag__file_get_binary_stdout()
176
FILE *grabbag__file_get_binary_stdout(void)
130
178
/* if something breaks here it is probably due to the presence or
131
179
* absence of an underscore before the identifiers 'setmode',