6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * Indentation logic: 2-space
46 #include <process.h> /* getpid */
49 #include <wiretap/file_util.h>
50 #include <epan/filesystem.h>
54 #define U3_DEVICE_PATH_VAR "$U3_DEVICE_PATH"
56 static char *pid_file = NULL;
57 static char *u3devicepath = (char*)-1;
58 static gchar *newpath = NULL;
60 static char *u3_change_path(char *path, const char *old, const char *new);
71 ("U3_HOST_EXEC_PATH") != NULL);
75 void u3_register_pid()
88 ("U3_HOST_EXEC_PATH")) != NULL) {
92 pf_size = strlen(u3hostexecpath) + 32;
93 pid_file = g_malloc(pf_size);
95 g_snprintf(pid_file, pf_size, "%s\\%d.pid", u3hostexecpath, pid);
97 pid_fd = eth_open(pid_file, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
109 void u3_deregister_pid()
112 /* we don't care if we succeed or fail - u3utils may have deleted the file */
113 eth_unlink(pid_file);
122 char *u3_expand_device_path(char *path)
124 return u3_change_path(path, U3_DEVICE_PATH_VAR, NULL);
128 char *u3_contract_device_path(char *path)
130 return u3_change_path(path, NULL, U3_DEVICE_PATH_VAR);
133 static char *u3_change_path(char *path, const char *old, const char *new)
136 if(u3devicepath == (char*)-1) {
137 /* cache the device path */
152 if(newpath != NULL) {
157 if((path != NULL) && (u3devicepath != NULL) && (strncmp(path, old, strlen(old)) == 0)) {
159 newpath = g_strconcat(new, path + strlen(old), NULL);