oct->len = oct->size = status.st_size;
oct->buf = (unsigned char *) odr_malloc (out, oct->size);
- fread (oct->buf, 1, oct->size, inf);
- fclose (inf);
+ if (fread(oct->buf, 1, oct->size, inf) != oct->size)
+ {
+ printf("Incomplete read of file %s\n", fname);
+ }
+ if (fclose(inf))
+ {
+ printf("Close failed for file %s\n", fname);
+ }
segment->segmentRecords[segment->num_segmentRecords++] = rec;
static void close_session(void);
+static void marc_file_write(const char *buf, size_t sz);
+
ODR getODROutputStream(void)
{
return out;
sprintf(fname, "%s.%03d.raw", dump_file_prefix, no);
of = fopen(fname, "wb");
- fwrite(buf, 1, len, of);
-
- fclose(of);
+ if (fwrite(buf, 1, len, of) != len)
+ {
+ printf("write failed for %s", fname);
+ }
+ if (fclose(of))
+ {
+ printf("close failed for %s", fname);
+ }
}
}
}
{
print_record((const unsigned char *) r->u.octet_aligned->buf,
r->u.octet_aligned->len);
- if (marc_file)
- fwrite(r->u.octet_aligned->buf, 1, r->u.octet_aligned->len, marc_file);
+ marc_file_write(r->u.octet_aligned->buf, r->u.octet_aligned->len);
}
else if (oid && r->which == Z_External_octet)
{
if (yaz_marc_decode_buf(mt, octet_buf, r->u.octet_aligned->len,
&result, &rlen)> 0)
{
- fwrite(result, rlen, 1, stdout);
+ if (fwrite(result, rlen, 1, stdout) != 1)
+ {
+ printf("write to stdout failed\n");
+ }
}
else
{
r->u.octet_aligned->len);
}
}
- if (marc_file)
- fwrite(octet_buf, 1, r->u.octet_aligned->len, marc_file);
+ marc_file_write(octet_buf, r->u.octet_aligned->len);
}
else if (oid && !oid_oidcmp(oid, yaz_oid_recsyn_sutrs))
{
return;
}
print_record(r->u.sutrs->buf, r->u.sutrs->len);
- if (marc_file)
- fwrite(r->u.sutrs->buf, 1, r->u.sutrs->len, marc_file);
+ marc_file_write(r->u.sutrs->buf, r->u.sutrs->len);
}
else if (oid && !oid_oidcmp(oid, yaz_oid_recsyn_grs_1))
{
FILE* includeFile;
char line[102400], *cp;
- if(strlen(arg)<1) {
- fprintf(stderr,"Error in source command use a filename\n");
+ if (strlen(arg) < 1)
+ {
+ fprintf(stderr, "Error in source command use a filename\n");
return -1;
}
includeFile = fopen(arg, "r");
- if(!includeFile) {
- fprintf(stderr,"Unable to open file %s for reading\n",arg);
+ if (!includeFile)
+ {
+ fprintf(stderr, "Unable to open file %s for reading\n",arg);
return -1;
}
- while(!feof(includeFile)) {
- memset(line,0,sizeof(line));
- fgets(line,sizeof(line),includeFile);
+ while (!feof(includeFile)) {
+ memset(line, 0, sizeof(line));
+ if (!fgets(line, sizeof(line), includeFile))
+ {
+ perror("fgets");
+ break;
+ }
- if(strlen(line) < 2) continue;
- if(line[0] == '#') continue;
+ if (strlen(line) < 2) continue;
+ if (line[0] == '#') continue;
if ((cp = strrchr(line, '\n')))
*cp = '\0';
- if( echo ) {
- printf( "processing line: %s\n",line );
- };
+ if (echo)
+ printf("processing line: %s\n", line);
process_cmd_line(line);
}
- if(fclose(includeFile)<0) {
+ if (fclose(includeFile))
+ {
perror("unable to close include file");
exit(1);
}
int cmd_subshell(const char* args)
{
- if(strlen(args))
- system(args);
- else
- system(getenv("SHELL"));
-
+ int ret = system(strlen(args) ? args : getenv("SHELL"));
printf("\n");
+ if (ret)
+ {
+ printf("Exit %d\n", ret);
+ }
return 1;
}
return 1;
}
+static void marc_file_write(const char *buf, size_t sz)
+{
+ if (marc_file)
+ {
+ if (fwrite(buf, 1, sz, marc_file) != sz)
+ {
+ perror("marcfile write");
+ }
+ }
+}
/*
this command takes 3 arge {name class oid}
*/
printf("\n");
if (rec->recordData_buf && rec->recordData_len)
{
- fwrite(rec->recordData_buf, 1, rec->recordData_len, stdout);
- if (marc_file)
- fwrite(rec->recordData_buf, 1, rec->recordData_len, marc_file);
+ if (fwrite(rec->recordData_buf, 1, rec->recordData_len, stdout) !=
+ rec->recordData_len)
+ {
+ printf("write to stdout failed\n");
+ }
+ printf("%.*s", rec->recordData_len, rec->recordData_buf);
+ marc_file_write(rec->recordData_buf, rec->recordData_len);
}
else
printf("No data!");
close(1);
close(2);
open("/dev/null", O_RDWR);
- dup(0); dup(0);
+ if (dup(0) == -1)
+ return 1;
+ if (dup(0) == -1)
+ return 1;
close(hand[1]);
}
querystr = srw_req->query.pqf;
break;
}
- wrbuf_printf(wr, "SRWSearch ");
- wrbuf_printf(wr, srw_req->database);
- wrbuf_printf(wr, " ");
+ wrbuf_printf(wr, "SRWSearch %s ", srw_req->database);
if (srw_res->num_diagnostics)
wrbuf_printf(wr, "ERROR %s", srw_res->diagnostics[0].uri);
else if (*http_code != 200)
querystr = "";
}
- wrbuf_printf(wr, "SRWScan ");
- wrbuf_printf(wr, srw_req->database);
- wrbuf_printf(wr, " ");
+ wrbuf_printf(wr, "SRWScan %s ", srw_req->database);
if (srw_res->num_diagnostics)
wrbuf_printf(wr, "ERROR %s - ", srw_res->diagnostics[0].uri);
*sz = ftell(inf);
rewind(inf);
buf = (char *) odr_malloc(o, *sz);
- fread(buf, 1, *sz, inf);
+ if (fread(buf, 1, *sz, inf) != *sz)
+ yaz_log(YLOG_WARN|YLOG_ERRNO, "short read %s", fname);
fclose(inf);
return buf;
}
for (i = 0 ; i < req->num_databaseNames; i++){
if (i)
wrbuf_printf(wr, "+");
- wrbuf_printf(wr, req->databaseNames[i]);
+ wrbuf_puts(wr, req->databaseNames[i]);
}
wrbuf_printf(wr, " ");
{
if (i)
wrbuf_printf(wr, "+");
- wrbuf_printf(wr, req->databaseNames[i]);
+ wrbuf_puts(wr, req->databaseNames[i]);
}
wrbuf_printf(wr, " ");
{
if (i)
wrbuf_printf(wr, "+");
- wrbuf_printf(wr, req->inputResultSetNames[i]);
+ wrbuf_puts(wr, req->inputResultSetNames[i]);
}
wrbuf_printf(wr, ")->%s ",req->sortedResultSetName);
void statserv_setcontrol(statserv_options_block *block)
{
- chdir(gfs_root_dir);
+ if (gfs_root_dir[0])
+ {
+ if (chdir(gfs_root_dir))
+ yaz_log(YLOG_WARN|YLOG_ERRNO, "chdir %s", gfs_root_dir);
+ }
#ifdef WIN32
if (init_control_tls)
TlsSetValue(current_control_tls, block);
close(1);
close(2);
open("/dev/null", O_RDWR);
- dup(0); dup(0);
+ if (dup(0) == -1)
+ return 1;
+ if (dup(0) == -1)
+ return 1;
}
xml_config_add_listeners();
h->cerrno = CSYSERR;
return -1;
}
- chown(path, sp->uid, sp->gid);
- chmod(path, sp->umask != -1 ? sp->umask : 0666);
+ if (chown(path, sp->uid, sp->gid))
+ {
+ h->cerrno = CSYSERR;
+ return -1;
+ }
+ if (chmod(path, sp->umask != -1 ? sp->umask : 0666))
+ {
+ h->cerrno = CSYSERR;
+ return -1;
+ }
if (mode == CS_SERVER && listen(h->iofile, 100) < 0)
{
h->cerrno = CSYSERR;
r = yaz_marc_decode_buf(mt, buf, -1, &result, &len_result);
if (r > 0 && result)
{
- fwrite (result, len_result, 1, stdout);
+ if (fwrite(result, len_result, 1, stdout) != 1)
+ {
+ fprintf(stderr, "Write to stdout failed\n");
+ break;
+ }
}
if (r > 0 && cfile)
{
{
fprintf (stderr, "%d\n", i);
if (res->records[i].recordData_buf)
- fwrite(res->records[i].recordData_buf, 1,
- res->records[i].recordData_len, stderr);
+ {
+ fprintf(stderr, "%.*s",
+ res->records[i].recordData_len,
+ res->records[i].recordData_buf);
+ }
}
}
}
ret = z_soap_codec(encode, &soap_package,
&content_buf, &content_len, h);
if (content_buf && content_len)
- fwrite (content_buf, content_len, 1, stdout);
+ {
+ printf("%.*s", content_len, content_buf);
+ }
else
{
fprintf(stderr, "No output!\n");
}
if (1) {
FILE *F = fopen("req.apdu","w");
- fwrite ( buf_out, 1, len_out, F);
- fclose(F);
+ if (!F)
+ {
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "open req.apdu failed");
+ }
+ else
+ {
+ if (fwrite ( buf_out, 1, len_out, F) != len_out)
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "write req.apdu failed");
+ if (fclose(F))
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "write req.apdu failed");
+ }
}
} /* sendrequest */
exit(4);
}
else
- fwrite(buf_out, len_out, 1, stdout);
+ {
+ if (fwrite(buf_out, len_out, 1, stdout) != 1)
+ {
+ fprintf(stderr, "%s: write failed\n", prog);
+ exit(5);
+ }
+ }
xmlFreeDoc(doc);
}
}
rewind(f);
xmlstr = (char *) xmalloc(sz+1);
xmlstr[sz] = '\0';
- fread(xmlstr, sz, 1, f);
- fclose(f);
+ if (fread(xmlstr, sz, 1, f) != 1)
+ {
+ fprintf(stderr, "%s: read failed for file %s\n", prog, xmlfile);
+ exit(1);
+ }
+ if (fclose(f))
+ {
+ fprintf(stderr, "%s: close failed for file %s\n", prog, xmlfile);
+ exit(1);
+ }
xmlquerytopqf(xmlstr);
xfree(xmlstr);
#define CHUNK_IN 64
#define CHUNK_OUT 64
+void write_out(const char *b0, const char *b1)
+{
+ size_t sz = b1 - b0;
+ if (sz)
+ {
+ if (fwrite(b0, 1, sz, stdout) != sz)
+ {
+ fprintf(stderr, "yaz-iconv: write failed\n");
+ exit(8);
+ }
+ }
+}
+
void convert(FILE *inf, yaz_iconv_t cd, int verbose)
{
char inbuf0[CHUNK_IN], *inbuf = inbuf0;
{
if (ferror(inf))
{
- fprintf(stderr, "yaziconv: error reading file\n");
+ fprintf(stderr, "yaz-iconv: error reading file\n");
exit(6);
}
if (r == 0)
{
- if (outbuf != outbuf0)
- fwrite(outbuf0, 1, outbuf - outbuf0, stdout);
+ write_out(outbuf0, outbuf);
outbuf = outbuf0;
outbytesleft = CHUNK_OUT;
r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
- if (outbuf != outbuf0)
- fwrite(outbuf0, 1, outbuf - outbuf0, stdout);
+ write_out(outbuf0, outbuf);
break;
}
inbytesleft = r;
{
if (ferror(inf))
{
- fprintf(stderr, "yaziconv: error reading file\n");
+ fprintf(stderr, "yaz-iconv: error reading file\n");
exit(6);
}
}
}
else if (e == YAZ_ICONV_E2BIG) /* no more output space */
{
- fwrite(outbuf0, 1, outbuf - outbuf0, stdout);
+ write_out(outbuf0, outbuf);
outbuf = outbuf0;
outbytesleft = CHUNK_OUT;
mustread = 0;
}
else
{
- fprintf(stderr, "yaziconv: unknown error\n");
+ fprintf(stderr, "yaz-iconv: unknown error\n");
exit(7);
}
}
inbuf = inbuf0;
inbytesleft = CHUNK_IN;
- fwrite(outbuf0, 1, outbuf - outbuf0, stdout);
+ write_out(outbuf0, outbuf);
outbuf = outbuf0;
outbytesleft = CHUNK_OUT;
inf = fopen(arg, "rb");
if (!inf)
{
- fprintf(stderr, "yaziconv: cannot open %s", arg);
+ fprintf(stderr, "yaz-iconv: cannot open %s", arg);
exit(2);
}
break;
verbose++;
break;
default:
- fprintf(stderr, "yaziconv: Usage\n"
+ fprintf(stderr, "yaz-iconv: Usage\n"
"yaziconv -f encoding -t encoding [-v] [file]\n");
exit(1);
}
}
if (!to)
{
- fprintf(stderr, "yaziconv: -t encoding missing\n");
+ fprintf(stderr, "yaz-iconv: -t encoding missing\n");
exit(3);
}
if (!from)
{
- fprintf(stderr, "yaziconv: -f encoding missing\n");
+ fprintf(stderr, "yaz-iconv: -f encoding missing\n");
exit(4);
}
cd = yaz_iconv_open(to, from);
if (!cd)
{
- fprintf(stderr, "yaziconv: unsupported encoding\n");
+ fprintf(stderr, "yaz-iconv: unsupported encoding\n");
exit(5);
}
else
{
if (verbose)
{
- fprintf(stderr, "yaziconv: using %s\n",
+ fprintf(stderr, "yaz-iconv: using %s\n",
yaz_iconv_isbuiltin(cd) ? "YAZ" : "iconv");
}
}
pos, (db ? db : "unknown"), syntax,
schema ? schema : "unknown");
if (render)
- fwrite(render, 1, len, stdout);
+ {
+ if (write(render, 1, len, stdout) != len)
+ {
+ printf("write to stdout failed\n");
+ }
+ }
printf("\n");
if (opac_render)
- fwrite(opac_render, 1, opac_len, stdout);
+ {
+ if (fwrite(opac_render, 1, opac_len, stdout) != opac_len)
+ printf("write to stdout failed\n");
+ }
}
}
}
int len = 0;
const char *term = ZOOM_scanset_display_term(s[i], p,
&occ, &len);
- fwrite(term, 1, len, stdout);
- printf(" %d\n", occ);
+
+ printf("%.*s %d\n", len, term, occ);
}
ZOOM_scanset_destroy(s[i]);
}
ZOOM_resultset_record (r[i], pos), "render", &len);
/* if rec is non-null, we got a record for display */
if (rec)
- {
- printf ("%d\n", pos+1);
- if (rec)
- fwrite (rec, 1, len, stdout);
- printf ("\n");
- }
+ printf ("%d\n%.*s\n", pos+1, len, rec);
}
}
}
printf ("%d %s %s\n", pos+1, syntax,
(db ? db : "unknown"));
if (rec)
- fwrite (str, 1, len, stdout);
+ {
+ if (fwrite (str, 1, len, stdout) != len)
+ printf("write to stdout failed\n");
+ }
printf ("\n");
}
}
{
printf ("%d %s\n", pos+1, (db ? db : "unknown"));
if (render)
- fwrite (render, 1, len, stdout);
+ {
+ if (fwrite (render, 1, len, stdout) != len)
+ printf("write to stdout failed\n");
+ }
printf ("\n");
}
}