Skip to content

Commit f97307b

Browse files
committed
zio should not care about how a user creates a FILE (pipe, socket, popen,
etc).
1 parent 6402bfb commit f97307b

2 files changed

Lines changed: 2 additions & 46 deletions

File tree

zio.c

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
/*
22
* zio.c
33
* a generic input stream interface
4-
* $Id: zio.c,v 1.5 1997/06/13 13:49:16 lhf Exp $
4+
* $Id: zio.c,v 1.1 1997/06/16 16:50:22 roberto Exp roberto $
55
*/
66

77
#include <stdio.h>
88
#include <stdlib.h>
99
#include <string.h>
1010
#include "zio.h"
1111

12-
#ifdef POPEN
13-
FILE *popen();
14-
int pclose();
15-
#else
16-
#define popen(x,y) NULL /* that is, popen always fails */
17-
#define pclose(x) (-1)
18-
#endif
1912

2013
/* ----------------------------------------------------- memory buffers --- */
2114

@@ -24,18 +17,12 @@ static int zmfilbuf(ZIO* z)
2417
return EOZ;
2518
}
2619

27-
static int zmclose(ZIO* z)
28-
{
29-
return 1;
30-
}
31-
3220
ZIO* zmopen(ZIO* z, char* b, int size)
3321
{
3422
if (b==NULL) return NULL;
3523
z->n=size;
3624
z->p= (unsigned char *)b;
3725
z->filbuf=zmfilbuf;
38-
z->close=zmclose;
3926
z->u=NULL;
4027
return z;
4128
}
@@ -59,42 +46,17 @@ static int zffilbuf(ZIO* z)
5946
return *(z->p++);
6047
}
6148

62-
static int zfclose(ZIO* z)
63-
{
64-
if (z->u==stdin) return 0;
65-
return fclose(z->u);
66-
}
6749

6850
ZIO* zFopen(ZIO* z, FILE* f)
6951
{
7052
if (f==NULL) return NULL;
7153
z->n=0;
7254
z->p=z->buffer;
7355
z->filbuf=zffilbuf;
74-
z->close=zfclose;
7556
z->u=f;
7657
return z;
7758
}
7859

79-
ZIO* zfopen(ZIO* z, char* s, char* m)
80-
{
81-
return zFopen(z,fopen(s,m));
82-
}
83-
84-
/* -------------------------------------------------------------- pipes --- */
85-
86-
static int zpclose(ZIO* z)
87-
{
88-
return pclose(z->u);
89-
}
90-
91-
ZIO* zpopen(ZIO* z, char* s, char* m)
92-
{
93-
z=zFopen(z,popen(s,m));
94-
if (z==NULL) return NULL;
95-
z->close=zpclose;
96-
return z;
97-
}
9860

9961
/* --------------------------------------------------------------- read --- */
10062
int zread(ZIO *z, void *b, int n)

zio.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* zio.h
33
* a generic input stream interface
4-
* $Id: zio.h,v 1.3 1997/06/18 21:39:56 roberto Exp roberto $
4+
* $Id: zio.h,v 1.4 1997/06/19 18:55:28 roberto Exp roberto $
55
*/
66

77
#ifndef zio_h
@@ -13,8 +13,6 @@
1313

1414
/* For Lua only */
1515
#define zFopen luaZ_Fopen
16-
#define zfopen luaZ_fopen
17-
#define zpopen luaZ_popen
1816
#define zsopen luaZ_sopen
1917
#define zmopen luaZ_mopen
2018
#define zread luaZ_read
@@ -24,16 +22,13 @@
2422
typedef struct zio ZIO;
2523

2624
ZIO* zFopen(ZIO* z, FILE* f); /* open FILEs */
27-
ZIO* zfopen(ZIO* z, char* s, char* m); /* file by name */
28-
ZIO* zpopen(ZIO* z, char* s, char* m); /* pipe */
2925
ZIO* zsopen(ZIO* z, char* s); /* string */
3026
ZIO* zmopen(ZIO* z, char* b, int size); /* memory */
3127

3228
int zread(ZIO* z, void* b, int n); /* read next n bytes */
3329

3430
#define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z))
3531
#define zungetc(z) (++(z)->n,--(z)->p)
36-
#define zclose(z) (*(z)->close)(z)
3732

3833

3934

@@ -45,7 +40,6 @@ struct zio {
4540
int n; /* bytes still unread */
4641
unsigned char* p; /* current position in buffer */
4742
int (*filbuf)(ZIO* z);
48-
int (*close)(ZIO* z);
4943
void* u; /* additional data */
5044
unsigned char buffer[ZBSIZE]; /* buffer */
5145
};

0 commit comments

Comments
 (0)