1 /* mischelp.c - Miscellaneous helper functions
2 * Copyright (C) 1998, 2000, 2001, 2006, 2007 Free Software Foundation, Inc.
4 * This file is part of JNLIB.
6 * JNLIB is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 3 of
9 * the License, or (at your option) any later version.
11 * JNLIB is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #ifdef HAVE_W32_SYSTEM
25 # define WIN32_LEAN_AND_MEAN
27 #else /*!HAVE_W32_SYSTEM*/
28 # include <sys/types.h>
29 # include <sys/stat.h>
31 #endif /*!HAVE_W32_SYSTEM*/
33 #include "libjnlib-config.h"
34 #include "stringhelp.h"
38 /* Check whether the files NAME1 and NAME2 are identical. This is for
39 example achieved by comparing the inode numbers of the files. */
41 same_file_p (const char *name1
, const char *name2
)
45 /* First try a shortcut. */
46 if (!compare_filenames (name1
, name2
))
50 #ifdef HAVE_W32_SYSTEM
52 BY_HANDLE_FILE_INFORMATION info1
, info2
;
54 file1
= CreateFile (name1
, 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
55 if (file1
== INVALID_HANDLE_VALUE
)
56 yes
= 0; /* If we can't open the file, it is not the same. */
59 file2
= CreateFile (name2
, 0, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
60 if (file1
== INVALID_HANDLE_VALUE
)
61 yes
= 0; /* If we can't open the file, it is not the same. */
64 yes
= (GetFileInformationByHandle (file1
, &info1
)
65 && GetFileInformationByHandle (file2
, &info2
)
66 && info1
.dwVolumeSerialNumber
==info2
.dwVolumeSerialNumber
67 && info1
.nFileIndexHigh
== info2
.nFileIndexHigh
68 && info1
.nFileIndexLow
== info2
.nFileIndexLow
);
73 #else /*!HAVE_W32_SYSTEM*/
74 struct stat info1
, info2
;
76 yes
= (!stat (name1
, &info1
) && !stat (name2
, &info2
)
77 && info1
.st_dev
== info2
.st_dev
&& info1
.st_ino
== info2
.st_ino
);
78 #endif /*!HAVE_W32_SYSTEM*/
85 timegm() is a GNU function that might not be available everywhere.
86 It's basically the inverse of gmtime() - you give it a struct tm,
87 and get back a time_t. It differs from mktime() in that it handles
88 the case where the struct tm is UTC and the local environment isn't.
90 Note, that this replacement implementaion is not thread-safe!
92 Some BSDs don't handle the putenv("foo") case properly, so we use
93 unsetenv if the platform has it to remove environment variables.
97 timegm (struct tm
*tm
)
108 static char *old_zone
;
112 old_zone
= malloc(3+strlen(zone
)+1);
115 strcpy(old_zone
,"TZ=");
116 strcat(old_zone
,zone
);
132 #endif /*!HAVE_TIMEGM*/