/* file_util.h
* File utility definitions
*
- * $Id$
- *
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
- * 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 program 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.
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef __FILE_UTIL_H__
#define __FILE_UTIL_H__
+#include "config.h"
+
#include "ws_symbol_export.h"
#ifdef __cplusplus
#include <glib.h>
#ifdef _WIN32
-#include <io.h>
+#include <io.h> /* for _read(), _write(), etc. */
#include <gmodule.h>
#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h> /* for open() */
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> /* for read(), write(), close(), etc. */
#endif
+#include <sys/stat.h> /* for stat() and struct stat */
+
+/*
+ * Visual C++ on Win32 systems doesn't define these. (Old UNIX systems don't
+ * define them either.)
+ *
+ * Visual C++ on Win32 systems doesn't define S_IFIFO, it defines _S_IFIFO.
+ */
+#ifndef S_ISREG
+#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+#ifndef S_IFIFO
+#define S_IFIFO _S_IFIFO
+#endif
+#ifndef S_ISFIFO
+#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
+#endif
+#ifndef S_ISDIR
+#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#endif
+
+#include <stdio.h>
#ifdef _WIN32
* removing the target if necessary.
*/
-#include <stdio.h>
-
-WS_DLL_PUBLIC
-extern int ws_stdio_open (const gchar *filename, int flags, int mode);
-WS_DLL_PUBLIC
-extern int ws_stdio_rename (const gchar *oldfilename, const gchar *newfilename);
-WS_DLL_PUBLIC
-extern int ws_stdio_mkdir (const gchar *filename, int mode);
-WS_DLL_PUBLIC
-extern int ws_stdio_stat64 (const gchar *filename, ws_statb64 *buf);
-WS_DLL_PUBLIC
-extern int ws_stdio_unlink (const gchar *filename);
-WS_DLL_PUBLIC
-extern int ws_stdio_remove (const gchar *filename);
+WS_DLL_PUBLIC int ws_stdio_open (const gchar *filename, int flags, int mode);
+WS_DLL_PUBLIC int ws_stdio_rename (const gchar *oldfilename, const gchar *newfilename);
+WS_DLL_PUBLIC int ws_stdio_mkdir (const gchar *filename, int mode);
+WS_DLL_PUBLIC int ws_stdio_stat64 (const gchar *filename, ws_statb64 *buf);
+WS_DLL_PUBLIC int ws_stdio_unlink (const gchar *filename);
+WS_DLL_PUBLIC int ws_stdio_remove (const gchar *filename);
-WS_DLL_PUBLIC
-extern FILE * ws_stdio_fopen (const gchar *filename, const gchar *mode);
-WS_DLL_PUBLIC
-extern FILE * ws_stdio_freopen (const gchar *filename, const gchar *mode, FILE *stream);
+WS_DLL_PUBLIC FILE * ws_stdio_fopen (const gchar *filename, const gchar *mode);
+WS_DLL_PUBLIC FILE * ws_stdio_freopen (const gchar *filename, const gchar *mode, FILE *stream);
#define ws_open ws_stdio_open
#define ws_rename ws_stdio_rename
#define ws_write _write
#define ws_close _close
#define ws_dup _dup
+#define ws_fseek64 _fseeki64 /* use _fseeki64 for 64-bit offset support */
#define ws_fstat64 _fstati64 /* use _fstati64 for 64-bit size support */
+#define ws_ftell64 _ftelli64 /* use _ftelli64 for 64-bit offset support */
#define ws_lseek64 _lseeki64 /* use _lseeki64 for 64-bit offset support */
#define ws_fdopen _fdopen
+#define ws_fileno _fileno
+#define ws_isatty _isatty
+#define ws_getc_unlocked _fgetc_nolock
+
+/*
+ * Other CRT functions. getpid probably belongs in sys_util.h or proc_util.h
+ * but neither yet exist.
+ */
+#define ws_getpid _getpid
+#define ws_umask _umask
/* DLL loading */
*/
WS_DLL_PUBLIC
-void *ws_load_library(gchar *library_name);
+void *ws_load_library(const gchar *library_name);
/** Load a DLL using g_module_open.
* Only the system and program directories are searched.
WS_DLL_PUBLIC
GModule *ws_module_open(gchar *module_name, GModuleFlags flags);
-/*
- * utf8 version of getenv, needed to get win32 filename paths
- */
-WS_DLL_PUBLIC
-extern char *getenv_utf8(const char *varname);
-
/** Create or open a "Wireshark is running" mutex.
* Create or open a mutex which signals that Wireshark or its associated
* executables is running. Used by the installer to test for a running application.
*/
-WS_DLL_PUBLIC
-extern void create_app_running_mutex();
+WS_DLL_PUBLIC void create_app_running_mutex();
+
+/** Close our "Wireshark is running" mutex.
+ */
+WS_DLL_PUBLIC void close_app_running_mutex();
#else /* _WIN32 */
#define ws_read read
#define ws_write write
+#ifdef __cplusplus
+/*
+ * Just in case this is used in a class with a close method or member.
+ */
+#define ws_close ::close
+#else
#define ws_close close
+#endif
#define ws_dup dup
+#ifdef HAVE_FSEEKO
+#define ws_fseek64 fseeko /* AC_SYS_LARGEFILE should make off_t 64-bit */
+#define ws_ftell64 ftello /* AC_SYS_LARGEFILE should make off_t 64-bit */
+#else
+#define ws_fseek64(fh,offset,whence) fseek(fh,(long)(offset),whence)
+#define ws_ftell64 ftell
+#endif
#define ws_fstat64 fstat /* AC_SYS_LARGEFILE should make off_t 64-bit */
#define ws_lseek64 lseek /* AC_SYS_LARGEFILE should make off_t 64-bit */
#define ws_fdopen fdopen
+#define ws_fileno fileno
+#define ws_isatty isatty
+#define ws_getc_unlocked getc_unlocked
#define O_BINARY 0 /* Win32 needs the O_BINARY flag for open() */
+/* Other CRT functions */
+#define ws_getpid getpid
+#define ws_umask umask
+
#endif /* _WIN32 */
/* directory handling */
#define ws_dir_rewind g_dir_rewind
#define ws_dir_close g_dir_close
-/* XXX - remove include "dirent.h" */
-/* XXX - remove include "direct.h" */
-/* XXX - remove include "sys/stat.h" */
+/* XXX - remove include "sys/stat.h" from files that include this header */
/* XXX - update docs (e.g. README.developer) */
#ifdef __cplusplus