4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * Indentation logic: 2-space
42 #include <process.h> /* getpid */
45 #include <wsutil/file_util.h>
50 #define U3_DEVICE_PATH_VAR "$U3_DEVICE_PATH"
52 static char *pid_file = NULL;
53 static char *u3devicepath = (char*)-1;
54 static gchar *newpath = NULL;
56 static const char *u3_change_path(const char *path, const char *old, const char *new_u3devicepath);
58 gboolean u3_active(void)
67 ("U3_HOST_EXEC_PATH") != NULL);
71 void u3_runtime_info(GString *str)
74 char *u3devicepath_lcl = NULL;
75 char *u3deviceproduct = NULL;
83 ("U3_DEVICE_PRODUCT")) != NULL) {
84 g_string_append(str, " from the ");
85 g_string_append(str, u3deviceproduct);
87 g_string_append(str, " from a ");
90 g_string_append(str, " U3 device");
92 if((u3devicepath_lcl =
98 ("U3_DEVICE_PATH")) != NULL) {
99 g_string_append(str, " in drive ");
100 g_string_append(str, u3devicepath_lcl);
105 void u3_register_pid(void)
109 char *u3hostexecpath;
118 ("U3_HOST_EXEC_PATH")) != NULL) {
122 pf_size = (int) strlen(u3hostexecpath) + 32;
123 pid_file = (char *)g_malloc(pf_size);
125 g_snprintf(pid_file, pf_size, "%s\\%d.pid", u3hostexecpath, pid);
127 pid_fd = ws_open(pid_file, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
139 void u3_deregister_pid(void)
142 /* we don't care if we succeed or fail - u3utils may have deleted the file */
152 const char *u3_expand_device_path(const char *path)
154 return u3_change_path(path, U3_DEVICE_PATH_VAR, NULL);
158 const char *u3_contract_device_path(char *path)
160 return u3_change_path(path, NULL, U3_DEVICE_PATH_VAR);
163 static const char *u3_change_path(const char *path, const char *old, const char *new_u3devicepath)
166 if(u3devicepath == (char*)-1) {
167 /* cache the device path */
177 if(new_u3devicepath == NULL)
178 new_u3devicepath = u3devicepath;
182 if(newpath != NULL) {
187 if((path != NULL) && (u3devicepath != NULL) && (strncmp(path, old, strlen(old)) == 0)) {
189 newpath = g_strconcat(new_u3devicepath, path + strlen(old), NULL);
200 * Editor modelines - http://www.wireshark.org/tools/modelines.html
205 * indent-tabs-mode: nil
208 * ex: set shiftwidth=2 tabstop=8 expandtab:
209 * :indentSize=2:tabSize=8:noTabs=true: