"Fossies" - the Fresh Open Source Software Archive

Member "xdelta3-3.0.11/examples/test.h" (24 Mar 2015, 886 Bytes) of package /linux/misc/xdelta3-3.0.11.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (C) 2007 Josh MacDonald */
    2 
    3 #define NOT_MAIN 1
    4 
    5 #include "xdelta3.h"
    6 #include "xdelta3.c"
    7 
    8 static int read_whole_file(const char *name,
    9                uint8_t **buf_ptr,
   10                size_t *buf_len) {
   11   main_file file;
   12   int ret;
   13   xoff_t len;
   14   usize_t nread;
   15   main_file_init(&file);
   16   file.filename = name;
   17   ret = main_file_open(&file, name, XO_READ);
   18   if (ret != 0) {
   19     fprintf(stderr, "open failed\n");
   20     goto exit;
   21   }
   22   ret = main_file_stat(&file, &len);
   23   if (ret != 0) {
   24     fprintf(stderr, "stat failed\n");
   25     goto exit;
   26   }
   27   
   28   (*buf_len) = (size_t)len;
   29   (*buf_ptr) = (uint8_t*) main_malloc(*buf_len);
   30   ret = main_file_read(&file, *buf_ptr, *buf_len, &nread,
   31                "read failed");
   32   if (ret == 0 && *buf_len == nread) {
   33     ret = 0;
   34   } else {
   35     fprintf(stderr, "invalid read\n");
   36     ret = XD3_INTERNAL;
   37   }
   38  exit:
   39   main_file_cleanup(&file);
   40   return ret;
   41 }
   42