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

Comparing deliantra/server/common/porting.C (file contents):
Revision 1.2 by root, Tue Aug 29 08:01:35 2006 UTC vs.
Revision 1.3 by root, Wed Aug 30 16:30:37 2006 UTC

1/* 1/*
2 * static char *rcsid_porting_c = 2 * static char *rcsid_porting_c =
3 * "$Id: porting.C,v 1.2 2006/08/29 08:01:35 root Exp $"; 3 * "$Id: porting.C,v 1.3 2006/08/30 16:30:37 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
62#include <stdarg.h> 62#include <stdarg.h>
63/* Has to be after above includes so we don't redefine some values */ 63/* Has to be after above includes so we don't redefine some values */
64#include "global.h" 64#include "global.h"
65 65
66static unsigned int curtmp = 0; 66static unsigned int curtmp = 0;
67
68/* This is a list of the suffix, uncompress and compress functions. Thus,
69 * if you have some other compress program you want to use, the only thing
70 * that needs to be done is to extended this.
71 * The first entry must be NULL - this is what is used for non
72 * compressed files.
73 */
74EXTERN char *uncomp[NROF_COMPRESS_METHODS][3] = {
75 {NULL, NULL, NULL},
76 {".Z", UNCOMPRESS, COMPRESS},
77 {".gz", GUNZIP, GZIP},
78 {".bz2", BUNZIP, BZIP}
79};
80 67
81/***************************************************************************** 68/*****************************************************************************
82 * File related functions 69 * File related functions
83 ****************************************************************************/ 70 ****************************************************************************/
84 71
320 return ret; 307 return ret;
321} 308}
322#endif 309#endif
323 310
324 311
325/* This takes an err number and returns a string with a description of
326 * the error.
327 */
328char *strerror_local(int errnum)
329{
330#if defined(HAVE_STRERROR)
331 return(strerror(errnum));
332#else
333 return("strerror_local not implemented");
334#endif
335}
336
337/* 312/*
338 * Based on (n+1)^2 = n^2 + 2n + 1 313 * Based on (n+1)^2 = n^2 + 2n + 1
339 * given that 1^2 = 1, then 314 * given that 1^2 = 1, then
340 * 2^2 = 1 + (2 + 1) = 1 + 3 = 4 315 * 2^2 = 1 + (2 + 1) = 1 + 3 = 4
341 * 3^2 = 4 + (4 + 1) = 4 + 5 = 1 + 3 + 5 = 9 316 * 3^2 = 4 + (4 + 1) = 4 + 5 = 1 + 3 + 5 = 9
374 static char tbuf[200]; 349 static char tbuf[200];
375 sprintf(tbuf,"%f",v); 350 sprintf(tbuf,"%f",v);
376 return tbuf; 351 return tbuf;
377} 352}
378 353
379/*
380 * A fast routine which appends the name and decimal number specified
381 * to the given buffer.
382 * Could be faster, though, if the strcat()s at the end could be changed
383 * into alternate strcat which returned a pointer to the _end_, not the
384 * start!
385 *
386 * Hey good news, it IS faster now, according to changes in get_ob_diff
387 * Completly redone prototype and made define in loader.l. See changes there.
388 * Didn't touch those for speed reason (don't use them anymore) .
389 * Tchize
390 */
391
392void save_long(char *buf, char *name, long n) {
393 char buf2[MAX_BUF];
394 strcpy(buf2,name);
395 strcat(buf2," ");
396 strcat(buf2,ltostr10(n));
397 strcat(buf2,"\n");
398 strcat(buf,buf2);
399}
400
401
402
403void save_long_long(char *buf, char *name, sint64 n) {
404 char buf2[MAX_BUF];
405
406#ifndef WIN32
407 sprintf(buf2,"%s %lld\n", name, n);
408#else
409 sprintf(buf2,"%s %I64d\n", name, n);
410#endif
411 strcat(buf,buf2);
412}
413
414/** 354/**
415 * Open and possibly uncompress a file. 355 * Open and possibly uncompress a file.
416 * 356 *
417 * @param ext the extension if the file is compressed. 357 * @param ext the extension if the file is compressed.
418 * 358 *
519 */ 459 */
520FILE *open_and_uncompress(const char *name, int flag, int *compressed) { 460FILE *open_and_uncompress(const char *name, int flag, int *compressed) {
521 size_t i; 461 size_t i;
522 FILE *fp; 462 FILE *fp;
523 463
524 for (i = 0; i < NROF_COMPRESS_METHODS; i++) {
525 *compressed = i;
526 fp = open_and_uncompress_file(uncomp[i][0], uncomp[i][1], name, flag, compressed); 464 fp = open_and_uncompress_file(0,0, name, flag, compressed);
527 if (fp != NULL) { 465 if (fp != NULL) {
528 return fp; 466 return fp;
529 } 467 }
530 }
531 468
532 errno = ENOENT; 469 errno = ENOENT;
533 return NULL; 470 return NULL;
534} 471}
535 472
559 496
560 while ((cp = strchr (cp + 1, (int) '/'))) { 497 while ((cp = strchr (cp + 1, (int) '/'))) {
561 *cp = '\0'; 498 *cp = '\0';
562 if (stat(buf, &statbuf) || !S_ISDIR (statbuf.st_mode)) { 499 if (stat(buf, &statbuf) || !S_ISDIR (statbuf.st_mode)) {
563 if (mkdir (buf, SAVE_DIR_MODE)) { 500 if (mkdir (buf, SAVE_DIR_MODE)) {
564 LOG(llevError, "Cannot mkdir %s: %s\n", buf, strerror_local(errno)); 501 LOG(llevError, "Cannot mkdir %s: %s\n", buf, strerror(errno));
565 return; 502 return;
566 } 503 }
567 } 504 }
568 *cp = '/'; 505 *cp = '/';
569 } 506 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines