- if (fnmatch (pattern_str, ent->d_name, 0) == 0)
- {
- char fname[1024];
- struct stat status;
- FILE *inf;
-
- sprintf (fname, "%s%s%s", dir_str, sep, ent->d_name);
- stat (fname, &status);
-
- if (S_ISREG(status.st_mode) && (inf = fopen(fname, "r")))
- {
- Z_NamePlusRecord *rec;
- Odr_oct *oct = (Odr_oct *) odr_malloc (out, sizeof(*oct));
-
- if (!apdu)
- {
- apdu = zget_APDU(out, Z_APDU_segmentRequest);
- segment = apdu->u.segmentRequest;
- segment->segmentRecords = (Z_NamePlusRecord **)
- odr_malloc (out, chunk * sizeof(*segment->segmentRecords));
- }
- rec = (Z_NamePlusRecord *) odr_malloc (out, sizeof(*rec));
- rec->databaseName = 0;
- rec->which = Z_NamePlusRecord_intermediateFragment;
- rec->u.intermediateFragment = (Z_FragmentSyntax *)
- odr_malloc (out, sizeof(*rec->u.intermediateFragment));
- rec->u.intermediateFragment->which =
- Z_FragmentSyntax_notExternallyTagged;
- rec->u.intermediateFragment->u.notExternallyTagged = oct;
-
- 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);
-
- segment->segmentRecords[segment->num_segmentRecords++] = rec;
-
- if (segment->num_segmentRecords == chunk)
- {
- send_apdu (apdu);
- apdu = 0;
- }
- }
- }
+ if (fnmatch (pattern_str, ent->d_name, 0) == 0)
+ {
+ char fname[1024];
+ struct stat status;
+ FILE *inf;
+
+ sprintf (fname, "%s%s%s", dir_str, sep, ent->d_name);
+ stat (fname, &status);
+
+ if (S_ISREG(status.st_mode) && (inf = fopen(fname, "r")))
+ {
+ Z_NamePlusRecord *rec;
+ Odr_oct *oct = (Odr_oct *) odr_malloc (out, sizeof(*oct));
+
+ if (!apdu)
+ {
+ apdu = zget_APDU(out, Z_APDU_segmentRequest);
+ segment = apdu->u.segmentRequest;
+ segment->segmentRecords = (Z_NamePlusRecord **)
+ odr_malloc (out, chunk * sizeof(*segment->segmentRecords));
+ }
+ rec = (Z_NamePlusRecord *) odr_malloc (out, sizeof(*rec));
+ rec->databaseName = 0;
+ rec->which = Z_NamePlusRecord_intermediateFragment;
+ rec->u.intermediateFragment = (Z_FragmentSyntax *)
+ odr_malloc (out, sizeof(*rec->u.intermediateFragment));
+ rec->u.intermediateFragment->which =
+ Z_FragmentSyntax_notExternallyTagged;
+ rec->u.intermediateFragment->u.notExternallyTagged = oct;
+
+ oct->len = oct->size = status.st_size;
+ oct->buf = (unsigned char *) odr_malloc (out, oct->size);
+ if (fread(oct->buf, 1, oct->size, inf) != (size_t) 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;
+
+ if (segment->num_segmentRecords == chunk)
+ {
+ send_apdu (apdu);
+ apdu = 0;
+ }
+ }
+ }