/[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 372 by siliconforks, Mon Oct 27 20:36:23 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 fatal_source(const char * source_file, unsigned int line_number, const char * format, ...) {
65      fprintf(stderr, "%s:%s:%u: ", program, source_file, line_number);
66      va_list ap;
67      va_start(ap, format);
68      vfprintf(stderr, format, ap);
69      va_end(ap);
70      fputc('\n', stderr);
71      exit(EXIT_FAILURE);
72    }
73    
74    void warn_source(const char * source_file, unsigned int line_number, const char * format, ...) {
75      fprintf(stderr, "%s:%s:%u: ", program, source_file, line_number);
76      va_list ap;
77      va_start(ap, format);
78      vfprintf(stderr, format, ap);
79      va_end(ap);
80      fputc('\n', stderr);
81    }
82    
83    void version(void) {
84      printf("%s %s\n", program, VERSION);
85      printf("Character encoding support: ");
86    #if HAVE_ICONV
87      printf("iconv\n");
88    #elif HAVE_MULTIBYTETOWIDECHAR
89      printf("MultiByteToWideChar\n");
90    #else
91      printf("none\n");
92    #endif
93      exit(EXIT_SUCCESS);
94    }
95    
96  size_t addst(size_t x, size_t y) {  size_t addst(size_t x, size_t y) {
97    if (SIZE_MAX - x < y) {    if (SIZE_MAX - x < y) {
98      fatal("integer overflow");      fatal("integer overflow");
# Line 352  Line 394 
394    
395    copy_stream(source, destination);    copy_stream(source, destination);
396    
397    #ifndef _WIN32
398      /* copy permissions */
399      struct stat buf;
400      if (fstat(fileno(source), &buf) == -1) {
401        fatal("cannot stat file: %s", source_file);
402      }
403      fchmod(fileno(destination), buf.st_mode);
404    #endif
405    
406    fclose(source);    fclose(source);
407    fclose(destination);    fclose(destination);
408  }  }
# Line 394  Line 445 
445        head = recursive_dir_list(root, entry_wrt_root, head);        head = recursive_dir_list(root, entry_wrt_root, head);
446        free(entry_wrt_root);        free(entry_wrt_root);
447      }      }
448    #ifndef _WIN32
449        else if (S_ISLNK(buf.st_mode)) {
450          /* check what it points to */
451          xstat(entry, &buf);
452          if (S_ISREG(buf.st_mode)) {
453            struct DirListEntry * p = xmalloc(sizeof(struct DirListEntry));
454            p->name = entry_wrt_root;
455            p->next = head;
456            head = p;
457          }
458          else {
459            fatal("refusing to follow symbolic link: %s", entry);
460          }
461        }
462    #endif
463      else {      else {
464        fatal("unknown file type: %s", entry);        fatal("unknown file type: %s", entry);
465      }      }
# Line 417  Line 483 
483    }    }
484  }  }
485    
486  #ifndef HAVE_CLOSESOCKET  #ifndef HAVE_STRNDUP
487  int closesocket(int s) {  char * strndup(const char * s, size_t size) {
488    return close(s);    size_t length = strlen(s);
489      if (length > size) {
490        char * result = xmalloc(size + 1);
491        strncpy(result, s, size);
492        result[size] = '\0';
493        return result;
494      }
495      else {
496        char * result = xmalloc(length + 1);
497        strcpy(result, s);
498        return result;
499      }
500  }  }
501  #endif  #endif
502    

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

  ViewVC Help
Powered by ViewVC 1.1.24