static void add_subdoc(xar_t x) { xar_subdoc_t s; int fd; unsigned char *buf; unsigned int len; struct stat sb; if( SubdocName == NULL ) SubdocName = "subdoc"; s = xar_subdoc_new(x, (const char *)SubdocName); fd = open(Subdoc, O_RDONLY); if( fd < 0 ) return; fstat(fd, &sb); len = sb.st_size; buf = malloc(len+1); if( buf == NULL ) { close(fd); return; } memset(buf, 0, len+1); read(fd, buf, len); close(fd); xar_subdoc_copyin(s, buf, len); return; }
static void add_subdoc(xar_t x) { xar_subdoc_t s; int fd; unsigned char *buf; unsigned int len; struct stat sb; if( SubdocName == NULL ) SubdocName = "subdoc"; fd = open(Subdoc, O_RDONLY); if( fd < 0 ) { fprintf(stderr, "ERROR: subdoc file %s doesn't exist. Ignoring.\n", Subdoc); return; } s = xar_subdoc_new(x, (const char *)SubdocName); fstat(fd, &sb); len = sb.st_size; buf = malloc(len+1); if( buf == NULL ) { close(fd); return; } memset(buf, 0, len+1); read(fd, buf, len); close(fd); xar_subdoc_copyin(s, buf, len); return; }