+static int record_read (int fd, char *buf, size_t count)
+{
+ return read (fd, buf, count);
+}
+
+static int record_fetch (ZServerInfo *zi, int sysno, int score, ODR stream,
+ oid_value input_format, Z_RecordComposition *comp,
+ oid_value *output_format, char **rec_bufp,
+ int *rec_lenp)
+{
+#if RECORD_BASE
+ Record rec;
+#else
+ char record_info[SYS_IDX_ENTRY_LEN];
+#endif
+ char *fname, *file_type;
+ RecType rt;
+ struct recRetrieveCtrl retrieveCtrl;
+
+#if RECORD_BASE
+ rec = rec_get (zi->records, sysno);
+ file_type = rec->info[0];
+ fname = rec->info[1];
+#else
+ if (lseek (zi->sys_idx_fd, sysno * SYS_IDX_ENTRY_LEN,
+ SEEK_SET) == -1)
+ {
+ logf (LOG_FATAL|LOG_ERRNO, "Retrieve: lseek of sys_idx");
+ exit (1);
+ }
+ if (read (zi->sys_idx_fd, record_info, SYS_IDX_ENTRY_LEN) == -1)
+ {
+ logf (LOG_FATAL|LOG_ERRNO, "Retrieve: read of sys_idx");
+ exit (1);
+ }
+ file_type = record_info;
+ fname = record_info + strlen(record_info) + 1;
+#endif
+
+ if (!(rt = recType_byName (file_type)))
+ {
+ logf (LOG_FATAL|LOG_ERRNO, "Retrieve: Cannot handle type %s",
+ file_type);
+ exit (1);
+ }
+ logf (LOG_DEBUG, "retrieve localno=%d score=%d", sysno, score);
+ if ((retrieveCtrl.fd = open (fname, O_RDONLY)) == -1)
+ {
+ char *msg = "Record doesn't exist";
+ logf (LOG_WARN|LOG_ERRNO, "Retrieve: Open record file %s", fname);
+ *output_format = VAL_SUTRS;
+ *rec_bufp = msg;
+ *rec_lenp = strlen (msg);
+#if RECORD_BASE
+ rec_rm (rec);
+#endif
+ return 0; /* or 14: System error in presenting records */
+ }
+ retrieveCtrl.localno = sysno;
+ retrieveCtrl.score = score;
+ retrieveCtrl.odr = stream;
+ retrieveCtrl.readf = record_read;
+ retrieveCtrl.input_format = retrieveCtrl.output_format = input_format;
+ retrieveCtrl.comp = comp;
+ retrieveCtrl.diagnostic = 0;
+ (*rt->retrieve)(&retrieveCtrl);
+ *output_format = retrieveCtrl.output_format;
+ *rec_bufp = retrieveCtrl.rec_buf;
+ *rec_lenp = retrieveCtrl.rec_len;
+ close (retrieveCtrl.fd);
+#if RECORD_BASE
+ rec_rm (rec);
+#endif
+ return retrieveCtrl.diagnostic;
+}
+