ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/path.C
(Generate patch)

Comparing deliantra/server/common/path.C (file contents):
Revision 1.9 by root, Mon Oct 12 14:00:57 2009 UTC vs.
Revision 1.10 by root, Thu Oct 15 20:45:01 2009 UTC

24 24
25#include <assert.h> 25#include <assert.h>
26#include <stdio.h> 26#include <stdio.h>
27#include <string.h> 27#include <string.h>
28#include <global.h> 28#include <global.h>
29#include <limits.h>
29 30
30#include "define.h" 31#include "define.h"
31#include "path.h" 32#include "path.h"
32 33
34#ifndef PATH_MAX
35# define PATH_MAX 8192
36#endif
33 37
34#if 0 38#if 0
35 39
36/** 40/**
37 * Define DEBUG_PATH to enable debug output. 41 * Define DEBUG_PATH to enable debug output.
55 59
56char * 60char *
57path_combine (const char *src, const char *dst) 61path_combine (const char *src, const char *dst)
58{ 62{
59 char *p; 63 char *p;
60 static char path[HUGE_BUF]; 64 static char path[PATH_MAX];
61 65
62 if (*dst == '/') 66 if (*dst == '/')
63 { 67 {
64 /* absolute destination path => ignore source path */ 68 /* absolute destination path => ignore source path */
65 strcpy (path, dst); 69 strcpy (path, dst);
67 else 71 else
68 { 72 {
69 /* relative destination path => add after last '/' of source */ 73 /* relative destination path => add after last '/' of source */
70 strcpy (path, src); 74 strcpy (path, src);
71 p = strrchr (path, '/'); 75 p = strrchr (path, '/');
72 if (p != NULL) 76 if (p)
73 {
74 p++; 77 p++;
75 }
76 else 78 else
77 { 79 {
78 p = path; 80 p = path;
79 if (*src == '/') 81 if (*src == '/')
80 *p++ = '/'; 82 *p++ = '/';
81 } 83 }
84
82 strcpy (p, dst); 85 strcpy (p, dst);
83 } 86 }
84 87
85#if defined(DEBUG_PATH) 88#if defined(DEBUG_PATH)
86 LOG (llevDebug, "path_combine(%s, %s) = %s\n", src, dst, path); 89 LOG (llevDebug, "path_combine(%s, %s) = %s\n", src, dst, path);
87#endif 90#endif
88 return (path); 91 return path;
89} 92}
90 93
91void 94void
92path_normalize (char *path) 95path_normalize (char *path)
93{ 96{
207} 210}
208 211
209static void 212static void
210check_normalize (const char *path, const char *exp0) 213check_normalize (const char *path, const char *exp0)
211{ 214{
212 char tmp[HUGE_BUF]; 215 char tmp[PATH_MAX];
213 char exp[HUGE_BUF]; 216 char exp[PATH_MAX];
214 217
215 strcpy (exp, exp0 == NULL ? path : exp0); 218 strcpy (exp, exp0 == NULL ? path : exp0);
216 219
217 strcpy (tmp, path); 220 strcpy (tmp, path);
218 fprintf (stderr, "path_normalize(%s) = ", tmp); 221 fprintf (stderr, "path_normalize(%s) = ", tmp);
219 path_normalize (tmp); 222 path_normalize (tmp);
220 fprintf (stderr, "%s", tmp); 223 fprintf (stderr, "%s", tmp);
221 if (strcmp (tmp, exp) != 0) 224 if (strcmp (tmp, exp) != 0)
222 {
223 fprintf (stderr, ", should be %s\n", exp); 225 fprintf (stderr, ", should be %s\n", exp);
224 }
225 else 226 else
226 {
227 fprintf (stderr, " (OK)\n"); 227 fprintf (stderr, " (OK)\n");
228 }
229} 228}
230 229
231static void 230static void
232check_combine_and_normalize (const char *src, const char *dst, const char *exp) 231check_combine_and_normalize (const char *src, const char *dst, const char *exp)
233{ 232{
235 234
236 fprintf (stderr, "path_combine_and_normalize(%s, %s) = ", src, dst); 235 fprintf (stderr, "path_combine_and_normalize(%s, %s) = ", src, dst);
237 res = path_combine_and_normalize (src, dst); 236 res = path_combine_and_normalize (src, dst);
238 fprintf (stderr, "%s", res); 237 fprintf (stderr, "%s", res);
239 if (strcmp (res, exp) != 0) 238 if (strcmp (res, exp) != 0)
240 {
241 fprintf (stderr, ", should be %s\n", exp); 239 fprintf (stderr, ", should be %s\n", exp);
242 }
243 else 240 else
244 {
245 fprintf (stderr, " (OK)\n"); 241 fprintf (stderr, " (OK)\n");
246 }
247} 242}
248 243
249int 244int
250main () 245main ()
251{ 246{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines