LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2008 INRIA | 3 * Copyright (c) 2008 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 #endif | 50 #endif |
51 | 51 |
52 #ifdef __linux__ | 52 #ifdef __linux__ |
53 #include <unistd.h> | 53 #include <unistd.h> |
54 #endif | 54 #endif |
55 | 55 |
56 /** | 56 /** |
57 * \def SYSTEM_PATH_SEP | 57 * \def SYSTEM_PATH_SEP |
58 * System-specific path separator used between directory names. | 58 * System-specific path separator used between directory names. |
59 */ | 59 */ |
60 #if defined (WIN32) | 60 #if defined (__win32__) |
61 #define SYSTEM_PATH_SEP "\\" | 61 #define SYSTEM_PATH_SEP "\\" |
62 #define WIN32_LEAN_AND_MEAN | |
63 #include <windows.h> | |
64 #else | 62 #else |
65 #define SYSTEM_PATH_SEP "/" | 63 #define SYSTEM_PATH_SEP "/" |
66 #endif | 64 #endif |
67 | 65 |
68 /** | 66 /** |
69 * \file | 67 * \file |
70 * \ingroup systempath | 68 * \ingroup systempath |
71 * ns3::SystemPath implementation. | 69 * ns3::SystemPath implementation. |
72 */ | 70 */ |
73 | 71 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 buffer = (char*)malloc (size); | 125 buffer = (char*)malloc (size); |
128 memset (buffer, 0, size); | 126 memset (buffer, 0, size); |
129 } | 127 } |
130 if (status == -1) | 128 if (status == -1) |
131 { | 129 { |
132 NS_FATAL_ERROR ("Oops, could not find self directory."); | 130 NS_FATAL_ERROR ("Oops, could not find self directory."); |
133 } | 131 } |
134 filename = buffer; | 132 filename = buffer; |
135 free (buffer); | 133 free (buffer); |
136 } | 134 } |
137 #elif defined (WIN32) | 135 #elif defined (__win32__) |
138 { | 136 { |
139 /** \todo untested. it should work if code is compiled with | 137 /** \todo untested. it should work if code is compiled with |
140 * LPTSTR = char * | 138 * LPTSTR = char * |
141 */ | 139 */ |
142 DWORD size = 1024; | 140 DWORD size = 1024; |
143 LPTSTR lpFilename = (LPTSTR) malloc (sizeof(TCHAR) * size); | 141 LPTSTR lpFilename = (LPTSTR) malloc (sizeof(TCHAR) * size); |
144 DWORD status = GetModuleFileName(0, lpFilename, size); | 142 DWORD status = GetModuleFilename (0, lpFilename, size); |
145 while (status == size) | 143 while (status == size) |
146 { | 144 { |
147 size = size * 2; | 145 size = size * 2; |
148 free (lpFilename); | 146 free (lpFilename); |
149 lpFilename = (LPTSTR) malloc (sizeof(TCHAR) * size); | 147 lpFilename = (LPTSTR) malloc (sizeof(TCHAR) * size); |
150 » status = GetModuleFileName(0, lpFilename, size); | 148 » status = GetModuleFilename (0, lpFilename, size); |
151 } | 149 } |
152 NS_ASSERT (status != 0); | 150 NS_ASSERT (status != 0); |
153 filename = lpFilename; | 151 filename = lpFilename; |
154 free (lpFilename); | 152 free (lpFilename); |
155 } | 153 } |
156 #elif defined (__APPLE__) | 154 #elif defined (__APPLE__) |
157 { | 155 { |
158 uint32_t bufsize = 1024; | 156 uint32_t bufsize = 1024; |
159 char *buffer = (char *) malloc (bufsize); | 157 char *buffer = (char *) malloc (bufsize); |
160 NS_ASSERT (buffer != 0); | 158 NS_ASSERT (buffer != 0); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 while (de != 0) | 253 while (de != 0) |
256 { | 254 { |
257 files.push_back (de->d_name); | 255 files.push_back (de->d_name); |
258 de = readdir (dp); | 256 de = readdir (dp); |
259 } | 257 } |
260 closedir (dp); | 258 closedir (dp); |
261 #elif defined (HAVE_FIND_FIRST_FILE) | 259 #elif defined (HAVE_FIND_FIRST_FILE) |
262 /** \todo untested */ | 260 /** \todo untested */ |
263 HANDLE hFind; | 261 HANDLE hFind; |
264 WIN32_FIND_DATA fileData; | 262 WIN32_FIND_DATA fileData; |
265 std::string wildcard = path + "\\*"; | 263 ·· |
266 | 264 hFind = FindFirstFile (path.c_str (), &FindFileData); |
267 hFind = FindFirstFile (wildcard.c_str (), &fileData); | |
268 if (hFind == INVALID_HANDLE_VALUE) | 265 if (hFind == INVALID_HANDLE_VALUE) |
269 { | 266 { |
270 NS_FATAL_ERROR ("Could not open directory=" << path); | 267 NS_FATAL_ERROR ("Could not open directory=" << path); |
271 } | 268 } |
272 do | 269 do |
273 { | 270 { |
274 » if (strcmp(fileData.cFileName, ".") != 0 && strcmp(fileData.cFileName, "
..") != 0) | 271 files.push_back (fileData.cFileName); |
275 files.push_back (fileData.cFileName); | |
276 } while (FindNextFile (hFind, &fileData)); | 272 } while (FindNextFile (hFind, &fileData)); |
277 FindClose(hFind); | 273 FindClose(hFind); |
278 #else | 274 #else |
279 #error "No support for reading a directory on this platform" | 275 #error "No support for reading a directory on this platform" |
280 #endif | 276 #endif |
281 return files; | 277 return files; |
282 } | 278 } |
283 | 279 |
284 std::string· | 280 std::string· |
285 MakeTemporaryDirectoryName (void) | 281 MakeTemporaryDirectoryName (void) |
(...skipping 14 matching lines...) Expand all Loading... |
300 // | 296 // |
301 // Just in case the user wants to go back and find the output, we give | 297 // Just in case the user wants to go back and find the output, we give |
302 // a hint as to which dir we created by including a time hint. | 298 // a hint as to which dir we created by including a time hint. |
303 // | 299 // |
304 time_t now = time (NULL); | 300 time_t now = time (NULL); |
305 struct tm *tm_now = localtime (&now); | 301 struct tm *tm_now = localtime (&now); |
306 // | 302 // |
307 // But we also randomize the name in case there are multiple users doing | 303 // But we also randomize the name in case there are multiple users doing |
308 // this at the same time | 304 // this at the same time |
309 // | 305 // |
310 srand ((unsigned int)time (0)); | 306 srand (time (0)); |
311 long int n = rand (); | 307 long int n = rand (); |
312 | 308 |
313 // | 309 // |
314 // The final path to the directory is going to look something like | 310 // The final path to the directory is going to look something like |
315 //· | 311 //· |
316 // /tmp/ns3-14.30.29.32767 | 312 // /tmp/ns3-14.30.29.32767 |
317 // | 313 // |
318 // The first segment comes from one of the temporary directory env· | 314 // The first segment comes from one of the temporary directory env· |
319 // variables or /tmp if not found. The directory name starts with an | 315 // variables or /tmp if not found. The directory name starts with an |
320 // identifier telling folks who is making all of the temp directories | 316 // identifier telling folks who is making all of the temp directories |
(...skipping 15 matching lines...) Expand all Loading... |
336 // Make sure all directories on the path exist | 332 // Make sure all directories on the path exist |
337 std::list<std::string> elements = Split (path); | 333 std::list<std::string> elements = Split (path); |
338 for (std::list<std::string>::const_iterator i = elements.begin (); i != elemen
ts.end (); ++i) | 334 for (std::list<std::string>::const_iterator i = elements.begin (); i != elemen
ts.end (); ++i) |
339 { | 335 { |
340 std::string tmp = Join (elements.begin (), i); | 336 std::string tmp = Join (elements.begin (), i); |
341 #if defined(HAVE_MKDIR_H) | 337 #if defined(HAVE_MKDIR_H) |
342 if (mkdir (tmp.c_str (), S_IRWXU)) | 338 if (mkdir (tmp.c_str (), S_IRWXU)) |
343 { | 339 { |
344 NS_LOG_ERROR ("failed creating directory " << tmp); | 340 NS_LOG_ERROR ("failed creating directory " << tmp); |
345 } | 341 } |
346 #else | |
347 #ifdef WIN32 | |
348 if (CreateDirectory(tmp.c_str(), NULL)) | |
349 { | |
350 NS_LOG_ERROR("failed creating directory " << path); | |
351 } | |
352 #endif | |
353 #endif | 342 #endif |
354 } | 343 } |
355 | 344 |
356 // Make the final directory. Is this redundant with last iteration above? | 345 // Make the final directory. Is this redundant with last iteration above? |
357 #if defined(HAVE_MKDIR_H) | 346 #if defined(HAVE_MKDIR_H) |
358 if (mkdir (path.c_str (), S_IRWXU)) | 347 if (mkdir (path.c_str (), S_IRWXU)) |
359 { | 348 { |
360 NS_LOG_ERROR ("failed creating directory " << path); | 349 NS_LOG_ERROR ("failed creating directory " << path); |
361 } | 350 } |
362 #else | |
363 #ifdef WIN32 | |
364 if (CreateDirectory(path.c_str(), NULL)) | |
365 { | |
366 NS_LOG_ERROR("failed creating directory " << path); | |
367 } | |
368 #endif | |
369 #endif | 351 #endif |
370 | 352 |
371 } | 353 } |
372 | 354 |
373 } // namespace SystemPath | 355 } // namespace SystemPath |
374 | 356 |
375 } // namespace ns3 | 357 } // namespace ns3 |
LEFT | RIGHT |