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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * Indentation logic: 2-space
44 #include <process.h> /* getpid */
47 #include <wsutil/file_util.h>
49 #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 const char *u3_change_path(const char *path, const char *old, const char *new_u3devicepath);
62 gboolean u3_active(void)
71 ("U3_HOST_EXEC_PATH") != NULL);
75 void u3_runtime_info(GString *str)
78 char *u3devicepath_lcl = NULL;
79 char *u3deviceproduct = NULL;
87 ("U3_DEVICE_PRODUCT")) != NULL) {
88 g_string_append(str, " from the ");
89 g_string_append(str, u3deviceproduct);
91 g_string_append(str, " from a ");
94 g_string_append(str, " U3 device");
96 if((u3devicepath_lcl =
102 ("U3_DEVICE_PATH")) != NULL) {
103 g_string_append(str, " in drive ");
104 g_string_append(str, u3devicepath_lcl);
109 void u3_register_pid(void)
113 char *u3hostexecpath;
122 ("U3_HOST_EXEC_PATH")) != NULL) {
126 pf_size = (int) strlen(u3hostexecpath) + 32;
127 pid_file = (char *)g_malloc(pf_size);
129 g_snprintf(pid_file, pf_size, "%s\\%d.pid", u3hostexecpath, pid);
131 pid_fd = ws_open(pid_file, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
143 void u3_deregister_pid(void)
146 /* we don't care if we succeed or fail - u3utils may have deleted the file */
156 const char *u3_expand_device_path(const char *path)
158 return u3_change_path(path, U3_DEVICE_PATH_VAR, NULL);
162 const char *u3_contract_device_path(char *path)
164 return u3_change_path(path, NULL, U3_DEVICE_PATH_VAR);
167 static const char *u3_change_path(const char *path, const char *old, const char *new_u3devicepath)
170 if(u3devicepath == (char*)-1) {
171 /* cache the device path */
181 if(new_u3devicepath == NULL)
182 new_u3devicepath = u3devicepath;
186 if(newpath != NULL) {
191 if((path != NULL) && (u3devicepath != NULL) && (strncmp(path, old, strlen(old)) == 0)) {
193 newpath = g_strconcat(new_u3devicepath, path + strlen(old), NULL);