~ubuntu-branches/ubuntu/karmic/flac/karmic

« back to all changes in this revision

Viewing changes to src/share/grabbag/file.c

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Kwan
  • Date: 2007-05-29 22:56:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529225636-ljeff8xxip09qaap
Tags: 1.1.4-1
* New upstream release. closes: #405167, #411311
  - libOggFLAC and libOggFLAC++ have been merged into libFLAC, so
    remove their corresponding packages.
  - Because of the API changes required to effect the above, there has
    been yet another soname bump. libflac7 -> libflac8 and
    libflac++5 -> libflac++6. Emails have been dispatched to the
    maintainers of dependent packages.
* Some notes on patches that were removed:
  - 02_stdin_stdout, 06_manpage_mention_utf8_convert: merged upstream
  - 08_manpage_warnings: Upstream has changed the manpage so it defintely
    can't fit in in 80 cols, so just forget about it. We'll live.
  - 05_eof_warnings_are_errors: Upstream decided to add a -w option to
    flac to treat all warnings as errors. I am going to defer to that
    for now, but if people think it's stupid let me know and I'll port
    the patch forward.
  - 04_stack_smasher: was a backport from 1.1.3, so it's obsolete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* grabbag - Convenience lib for various routines common to several tools
2
 
 * Copyright (C) 2002,2003,2004,2005  Josh Coalson
3
 
 *
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.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
 
2
 * Copyright (C) 2002,2003,2004,2005,2006,2007  Josh Coalson
 
3
 *
 
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.
 
8
 *
 
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.
13
13
 *
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
17
17
 */
18
18
 
 
19
#if HAVE_CONFIG_H
 
20
#  include <config.h>
 
21
#endif
 
22
 
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() */
26
30
#endif
27
 
#ifdef __CYGWIN__
 
31
#if defined __CYGWIN__ || defined __EMX__
28
32
#include <io.h> /* for setmode(), O_BINARY */
29
33
#include <fcntl.h> /* for _O_BINARY */
30
34
#endif
36
40
#include <stdio.h>
37
41
#include <stdlib.h>
38
42
#include <string.h> /* for strrchr() */
 
43
#if defined _WIN32 && !defined __CYGWIN__
 
44
// for GetFileInformationByHandle() etc
 
45
#include <Windows.h>
 
46
#include <Winbase.h>
 
47
#endif
39
48
#include "share/grabbag.h"
40
49
 
41
50
 
104
113
        return true;
105
114
}
106
115
 
 
116
FLAC__bool grabbag__file_are_same(const char *f1, const char *f2)
 
117
{
 
118
#if defined _MSC_VER || defined __MINGW32__
 
119
        /* see
 
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
 
125
         */
 
126
        FLAC__bool same = false;
 
127
        BY_HANDLE_FILE_INFORMATION info1, info2;
 
128
        HANDLE h1, h2;
 
129
        BOOL ok = 1;
 
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)
 
133
                ok = 0;
 
134
        ok &= GetFileInformationByHandle(h1, &info1);
 
135
        ok &= GetFileInformationByHandle(h2, &info2);
 
136
        if(ok)
 
137
                same =
 
138
                        info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber &&
 
139
                        info1.nFileIndexHigh == info2.nFileIndexHigh &&
 
140
                        info1.nFileIndexLow == info2.nFileIndexLow
 
141
                ;
 
142
        if(h1 != INVALID_HANDLE_VALUE)
 
143
                CloseHandle(h1);
 
144
        if(h2 != INVALID_HANDLE_VALUE)
 
145
                CloseHandle(h2);
 
146
        return same;
 
147
#else
 
148
        struct stat s1, s2;
 
149
        return f1 && f2 && stat(f1, &s1) == 0 && stat(f2, &s2) == 0 && s1.st_ino == s2.st_ino && s1.st_dev == s2.st_dev;
 
150
#endif
 
151
}
 
152
 
107
153
FLAC__bool grabbag__file_remove_file(const char *filename)
108
154
{
109
155
        return grabbag__file_change_stats(filename, /*read_only=*/false) && 0 == unlink(filename);
110
156
}
111
157
 
112
 
FILE *grabbag__file_get_binary_stdin()
 
158
FILE *grabbag__file_get_binary_stdin(void)
113
159
{
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);
123
171
#endif
124
172
 
125
173
        return stdin;
126
174
}
127
175
 
128
 
FILE *grabbag__file_get_binary_stdout()
 
176
FILE *grabbag__file_get_binary_stdout(void)
129
177
{
130
178
        /* if something breaks here it is probably due to the presence or
131
179
         * absence of an underscore before the identifiers 'setmode',
136
184
#elif defined __CYGWIN__
137
185
        /* almost certainly not needed for any modern Cygwin, but let's be safe... */
138
186
        setmode(_fileno(stdout), _O_BINARY);
 
187
#elif defined __EMX__
 
188
        setmode(fileno(stdout), O_BINARY);
139
189
#endif
140
190
 
141
191
        return stdout;