/[jscoverage]/trunk/util.c
ViewVC logotype

Diff of /trunk/util.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 106 by siliconforks, Sat May 31 07:37:39 2008 UTC revision 364 by siliconforks, Sun Oct 26 21:08:56 2008 UTC
# Line 47  Line 47 
47    vfprintf(stderr, format, ap);    vfprintf(stderr, format, ap);
48    va_end(ap);    va_end(ap);
49    fputc('\n', stderr);    fputc('\n', stderr);
50      exit(EXIT_FAILURE);
51    }
52    
53    void fatal_command_line(const char * format, ...) {
54      fprintf(stderr, "%s: ", program);
55      va_list ap;
56      va_start(ap, format);
57      vfprintf(stderr, format, ap);
58      va_end(ap);
59      fputc('\n', stderr);
60    fprintf(stderr, "Try `%s --help' for more information.\n", program);    fprintf(stderr, "Try `%s --help' for more information.\n", program);
61    exit(EXIT_FAILURE);    exit(EXIT_FAILURE);
62  }  }
63    
64    void version(void) {
65      printf("%s %s\n", program, VERSION);
66      printf("Character encoding support: ");
67    #if HAVE_ICONV
68      printf("iconv\n");
69    #elif HAVE_MULTIBYTETOWIDECHAR
70      printf("MultiByteToWideChar\n");
71    #else
72      printf("none\n");
73    #endif
74      exit(EXIT_SUCCESS);
75    }
76    
77  size_t addst(size_t x, size_t y) {  size_t addst(size_t x, size_t y) {
78    if (SIZE_MAX - x < y) {    if (SIZE_MAX - x < y) {
79      fatal("integer overflow");      fatal("integer overflow");
# Line 352  Line 375 
375    
376    copy_stream(source, destination);    copy_stream(source, destination);
377    
378    #ifndef _WIN32
379      /* copy permissions */
380      struct stat buf;
381      if (fstat(fileno(source), &buf) == -1) {
382        fatal("cannot stat file: %s", source_file);
383      }
384      fchmod(fileno(destination), buf.st_mode);
385    #endif
386    
387    fclose(source);    fclose(source);
388    fclose(destination);    fclose(destination);
389  }  }
# Line 394  Line 426 
426        head = recursive_dir_list(root, entry_wrt_root, head);        head = recursive_dir_list(root, entry_wrt_root, head);
427        free(entry_wrt_root);        free(entry_wrt_root);
428      }      }
429    #ifndef _WIN32
430        else if (S_ISLNK(buf.st_mode)) {
431          /* check what it points to */
432          xstat(entry, &buf);
433          if (S_ISREG(buf.st_mode)) {
434            struct DirListEntry * p = xmalloc(sizeof(struct DirListEntry));
435            p->name = entry_wrt_root;
436            p->next = head;
437            head = p;
438          }
439          else {
440            fatal("refusing to follow symbolic link: %s", entry);
441          }
442        }
443    #endif
444      else {      else {
445        fatal("unknown file type: %s", entry);        fatal("unknown file type: %s", entry);
446      }      }
# Line 417  Line 464 
464    }    }
465  }  }
466    
467  #ifndef HAVE_CLOSESOCKET  #ifndef HAVE_STRNDUP
468  int closesocket(int s) {  char * strndup(const char * s, size_t size) {
469    return close(s);    size_t length = strlen(s);
470      if (length > size) {
471        char * result = xmalloc(size + 1);
472        strncpy(result, s, size);
473        result[size] = '\0';
474        return result;
475      }
476      else {
477        char * result = xmalloc(length + 1);
478        strcpy(result, s);
479        return result;
480      }
481  }  }
482  #endif  #endif
483    

Legend:
Removed from v.106  
changed lines
  Added in v.364

  ViewVC Help
Powered by ViewVC 1.1.24