Galactic Bloodshed
files_rw.cc
Go to the documentation of this file.
1 // Copyright 2014 The Galactic Bloodshed Authors. All rights reserved.
2 // Use of this source code is governed by a license that can be
3 // found in the COPYING file.
4 
5 /* disk input/output routines */
6 
7 /*
8  * Fileread(p, num, file, posn, routine); -- generic file read
9  * Filewrite(p, num, file, posn, routine); -- generic file write
10  *
11  */
12 
13 #include "gb/files_rw.h"
14 
15 #include <sys/file.h>
16 #include <unistd.h>
17 
18 #include <cstdio>
19 
20 void Fileread(int fd, char *p, int num, int posn) {
21  int n2;
22 
23  if (lseek(fd, posn, L_SET) < 0) {
24  perror("Fileread 1");
25  return;
26  }
27  if ((n2 = read(fd, p, num)) != num) {
28  perror("Fileread 2");
29  }
30 }
31 
32 void Filewrite(int fd, char *p, int num, int posn) {
33  int n2;
34 
35  if (lseek(fd, posn, L_SET) < 0) {
36  perror("Filewrite 1");
37  return;
38  }
39 
40  if ((n2 = write(fd, p, num)) != num) {
41  perror("Filewrite 2");
42  return;
43  }
44 }
void Fileread(int, char *, int, int)
Definition: files_rw.cc:20
void Filewrite(int, char *, int, int)
Definition: files_rw.cc:32