socsvn commit: r255684 - in soc2013/dpl: . head/lib/libzcap head/lib/libzcap/zlibworker
dpl at FreeBSD.org
dpl at FreeBSD.org
Thu Aug 8 18:26:20 UTC 2013
Author: dpl
Date: Thu Aug 8 18:26:19 2013
New Revision: 255684
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255684
Log:
Made everything compilable.
Added:
soc2013/dpl/datapasstest.c
Modified:
soc2013/dpl/head/lib/libzcap/Makefile
soc2013/dpl/head/lib/libzcap/adler32.c
soc2013/dpl/head/lib/libzcap/capsicum.c
soc2013/dpl/head/lib/libzcap/commands.c
soc2013/dpl/head/lib/libzcap/compress.c
soc2013/dpl/head/lib/libzcap/crc32.c
soc2013/dpl/head/lib/libzcap/gzlib.c
soc2013/dpl/head/lib/libzcap/gzread.c
soc2013/dpl/head/lib/libzcap/gzwrite.c
soc2013/dpl/head/lib/libzcap/zlibworker/Makefile
soc2013/dpl/head/lib/libzcap/zlibworker/comands.c
soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c
Added: soc2013/dpl/datapasstest.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/dpl/datapasstest.c Thu Aug 8 18:26:19 2013 (r255684)
@@ -0,0 +1,50 @@
+#include <nv.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#define BIG 5*1024
+
+void * ptr;
+char *buf, *buf2;
+int sv[2];
+nvlist_t *nvl1, *nvl2;
+
+int
+main()
+{
+ int i= 0;
+ size_t big = BIG;
+
+ buf = malloc(BIG);
+ if (buf == NULL) {
+ perror("malloc()");
+ return 1;
+ }
+ for( i = 0; i < BIG; i++)
+ buf[i] = (char)random();
+
+ if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0 )
+ perror("socketpair");
+
+ nvl1 = nvlist_create(0);
+ nvl2 = nvlist_create(0);
+
+ nvlist_add_binary(nvl1, "data", buf, BIG);
+ nvlist_send(sv[0], nvl1);
+
+ nvl2 = nvlist_recv(sv[1]);
+ buf2 = malloc(BIG);
+ ptr = nvlist_take_binary(nvl2, "data", &big);
+ memcpy(buf2, ptr, BIG);
+
+ for( i = 0; i < BIG; i++)
+ assert( buf[i] == buf2[i]);
+ free(buf);
+
+ printf("Everything went well!\n");
+ return 0;
+}
\ No newline at end of file
Modified: soc2013/dpl/head/lib/libzcap/Makefile
==============================================================================
--- soc2013/dpl/head/lib/libzcap/Makefile Thu Aug 8 17:21:59 2013 (r255683)
+++ soc2013/dpl/head/lib/libzcap/Makefile Thu Aug 8 18:26:19 2013 (r255684)
@@ -3,7 +3,7 @@
#
#TODEL
-CFLAGS+= -Wall -g -fno-color-diagnostics
+CFLAGS+= -Wall -g -v -fno-color-diagnostics
LIB= zcap
SHLIBDIR?= /lib
Modified: soc2013/dpl/head/lib/libzcap/adler32.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/adler32.c Thu Aug 8 17:21:59 2013 (r255683)
+++ soc2013/dpl/head/lib/libzcap/adler32.c Thu Aug 8 18:26:19 2013 (r255684)
@@ -62,16 +62,16 @@
#endif
/* ========================================================================= */
-uLong zcapcmd_adler32();
+extern uLong zcapcmd_adler32();
uLong ZEXPORT adler32(adler, buf, len)
uLong adler;
const Bytef *buf;
uInt len;
{
/* Send packets of 100kb size at most. */
- if ((sizeof(*buf)*len) > (100*1024)) {
- while( (len -= (100*1024)) > 0) {
- buf += (100*1024)/sizeof(*buf);
+ if ((sizeof(*buf)*len) > (5*1024)) {
+ while( (len -= (5*1024)) > 0) {
+ buf += (5*1024)/sizeof(*buf);
adler = zcapcmd_adler32(adler, buf, len);
}
} else {
@@ -81,7 +81,7 @@
}
/* ========================================================================= */
-uLong zcapcmd_adler32_combine();
+extern uLong zcapcmd_adler32_combine();
local uLong adler32_combine_(adler1, adler2, len2)
uLong adler1;
uLong adler2;
Modified: soc2013/dpl/head/lib/libzcap/capsicum.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/capsicum.c Thu Aug 8 17:21:59 2013 (r255683)
+++ soc2013/dpl/head/lib/libzcap/capsicum.c Thu Aug 8 18:26:19 2013 (r255684)
@@ -1,6 +1,15 @@
#include "capsicum.h"
#include "zlib.h"
+#include <nv.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+
#define SUM 0
pid_t pid = 0;
@@ -8,6 +17,7 @@
int startChild(void);
void killChild(void);
+nvlist_t * sendCommand(nvlist_t *nvl);
int
startChild()
@@ -25,12 +35,12 @@
/* open and fexec() listener */
if (access("/usr/libexec/zlibworker", X_OK) < 0) {
- fprintf(stderr, "zlibworker doesn't exist, or can't be executed.\n")
+ fprintf(stderr, "zlibworker doesn't exist, or can't be executed.\n");
fprintf(stderr, "You should compile and install it.\n");
exit (-1);
}
- execve("/usr/libexec/zlibworker", "", "");
+ execl("/usr/libexec/zlibworker", "");
exit(0);
} else
atexit(killChild);
@@ -41,13 +51,19 @@
nvlist_t *
sendCommand( nvlist_t *nvl )
{
- if( nvlist_send(sv[0], nvl) == 0 )
- continue;
+ if( nvlist_send(sv[0], nvl) != 0 ) {
+ perror("nvlist_send()");
+ return NULL;
+ }
+
nvlist_destroy(nvl);
/* recv results */
- if ((nvl = nvlist_recv(sv[0])) != NULL)
- continue;
+ if ((nvl = nvlist_recv(sv[0])) != NULL) {
+ perror("nvlist_send()");
+ return NULL;
+ }
+
return (nvl);
}
Modified: soc2013/dpl/head/lib/libzcap/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.c Thu Aug 8 17:21:59 2013 (r255683)
+++ soc2013/dpl/head/lib/libzcap/commands.c Thu Aug 8 18:26:19 2013 (r255684)
@@ -34,14 +34,39 @@
*/
+#include "zlib.h"
#include "capsicum.c"
+#include "commands.h"
-extern pid;
+#include <string.h>
+
+
+uLong zcapcmd_compressBound(uLong sourceLen);
+
+gzFile zcapcmd_gzopen(const char *path, int fd, const char *mode);
+int zcapcmd_gzbuffer(gzFile file, unsigned size);
+int zcapcmd_gzsetparams(gzFile file, int level, int strategy);
+int zcapcmd_gzputs(gzFile file, const char *s);
+char *zcapcmd_gzgets(gzFile file, char *buf, int len);
+int zcapcmd_gzputc(gzFile file, int c);
+int zcapcmd_gzungetc(int c, gzFile file);
+int zcapcmd_gzflush(gzFile file, int flush);
+z_off_t zcapcmd_gzseek(gzFile file, z_off_t offset, int whence);
+int zcapcmd_simplecommand(gzFile file, int command);
+char * zcapcmd_gzerror(gzFile file, int *errnum);
+
+uLong zcapcmd_adler32(uLong adler, const Bytef *buf, uInt len);
+uLong zcapcmd_adler32_combine(uLong adler1, uLong adler2, z_off_t len2 );
+uLong zcapcmd_crc32(uLong crc, const Bytef *buf, uInt len);
+uLong zcapcmd_crc32_combine(uLong crc1, uLong crc2, z_off64_t len2);
+
+extern pid_t pid;
extern nvlist_t *sendCommand(nvlist_t *);
+size_t gzFilesize = sizeof(struct gzFile_s);
+
uLong
-zcapcmd_compressBound(sourceLen)
- uLong sourceLen;
+zcapcmd_compressBound(uLong sourceLen)
{
nvlist_t *nvl, *args, *result;
uLong ret;
@@ -52,7 +77,7 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_COMPRESSBOUND);
nvlist_add_number(args, "sourceLen", sourceLen);
@@ -60,16 +85,13 @@
result = sendCommand(nvl);
- int ret = nvlist_take_number(result, "result");
+ ret = nvlist_take_number(result, "result");
nvlist_destroy(result);
return(ret);
}
gzFile
-zcapcmd_gzopen(path, fd, mode)
- const char *path;
- int fd;
- const char *mode;
+zcapcmd_gzopen(const char *path, int fd, const char *mode)
{
nvlist_t *nvl, *args, *result;
@@ -89,18 +111,16 @@
result = sendCommand(nvl);
- void *mem = malloc(sizeof(gzFile_s));
+ void *mem = malloc(gzFilesize);
memcpy(mem,
- nvlist_take_binary(result, "result", sizeof(gzFile_s)),
- sizeof(gzFile_s));
+ nvlist_take_binary(result, "result", &gzFilesize),
+ gzFilesize);
nvlist_destroy(result);
- return(mem);
+ return((gzFile)mem);
}
int
-zcapcmd_gzbuffer(file, size)
- gzFile file;
- unsigned size;
+zcapcmd_gzbuffer(gzFile file, unsigned size)
{
nvlist_t *nvl, *args, *result;
@@ -110,10 +130,10 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_GZBUFFER);
- nvlist_add_binary(args, "file", file, sizeof(gzFile_s));
+ nvlist_add_binary(args, "file", file, gzFilesize);
nvlist_add_number(args, "size", size);
nvlist_add_nvlist(nvl, "args", args);
@@ -125,10 +145,7 @@
}
int
-zcapcmd_gzsetparams(file, level, strategy)
- gzFile file;
- int level;
- int strategy;
+zcapcmd_gzsetparams(gzFile file, int level, int strategy)
{
nvlist_t *nvl, *args, *result;
@@ -138,10 +155,10 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_GZSETPARAMS);
- nvlist_add_binary(args, "file", file, sizeof(gzFile_s));
+ nvlist_add_binary(args, "file", file, gzFilesize);
nvlist_add_number(args, "level", level);
nvlist_add_number(args, "strategy", strategy);
nvlist_add_nvlist(nvl, "args", args);
@@ -160,9 +177,7 @@
*/
int
-zcapcmd_gzputs(file, s)
- gzFile file;
- const char *s;
+zcapcmd_gzputs(gzFile file, const char *s)
{
nvlist_t *nvl, *args, *result;
@@ -172,25 +187,22 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_GZPUTS);
- nvlist_add_binary(args, "file", file, sizeof(gzFile_s));
+ nvlist_add_binary(args, "file", file, gzFilesize);
nvlist_add_string(args, "s", s);
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result");
+ int ret = nvlist_take_number(result, "result");
nvlist_destroy(result);
return(ret);
}
-/* XXX */
char *
-zcapcmd_gzgets(file, s)
- gzFile file;
- const char *s;
+zcapcmd_gzgets(gzFile file, char *buf, int len)
{
nvlist_t *nvl, *args, *result;
@@ -203,21 +215,23 @@
return (NULL);
}
nvlist_add_number(nvl, "command", ZCAPCMD_GZGETS);
- nvlist_add_binary(args, "file", file, sizeof(gzFile_s));
- nvlist_add_string(args, "s", s);
+ nvlist_add_binary(args, "file", file, gzFilesize);
+ nvlist_add_number(args, "len", len);
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
char *ret = nvlist_take_string(result, "result");
- nvlist_destroy(result);
- return(ret);
+ if (ret == NULL)
+ return NULL;
+ else
+ memcpy(buf, (void *)ret, len);
+ nvlist_destroy(result);
+ return(buf);
}
int
-zcapcmd_gzputc(file, c)
- gzFile file;
- int c;
+zcapcmd_gzputc(gzFile file, int c)
{
nvlist_t *nvl, *args, *result;
@@ -227,10 +241,10 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_GZPUTC);
- nvlist_add_binary(args, "file", file, sizeof(gzFile_s));
+ nvlist_add_binary(args, "file", file, gzFilesize);
nvlist_add_number(args, "c", c);
nvlist_add_nvlist(nvl, "args", args);
@@ -242,9 +256,7 @@
}
int
-zcapcmd_gzungetc(c, file)
- int c;
- gzFile file;
+zcapcmd_gzungetc(int c, gzFile file)
{
nvlist_t *nvl, *args, *result;
@@ -254,11 +266,11 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_GZUNGETC);
nvlist_add_number(args, "c", c);
- nvlist_add_binary(args, "file", file, sizeof(gzFile_s));
+ nvlist_add_binary(args, "file", file, gzFilesize);
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
@@ -269,9 +281,7 @@
}
int
-zcapcmd_gzflush(file, flush)
- gzFile file;
- int flush;
+zcapcmd_gzflush(gzFile file, int flush)
{
nvlist_t *nvl, *args, *result;
@@ -281,10 +291,10 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_GZFLUSH);
- nvlist_add_binary(args, "file", file, sizeof(gzFile_s));
+ nvlist_add_binary(args, "file", file, gzFilesize);
nvlist_add_number(args, "flush", flush);
nvlist_add_nvlist(nvl, "args", args);
@@ -296,10 +306,7 @@
}
z_off_t
-zcapcmd_gzseek(file, offset, whence)
- gzFile file;
- z_off_t flush;
- int whence;
+zcapcmd_gzseek(gzFile file, z_off_t offset, int whence)
{
nvlist_t *nvl, *args, *result;
@@ -309,10 +316,10 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_GZSEEK);
- nvlist_add_binary(args, "file", file, sizeof(gzFile_s));
+ nvlist_add_binary(args, "file", file, gzFilesize);
nvlist_add_number(args, "offset", offset);
nvlist_add_number(args, "whence", whence);
nvlist_add_nvlist(nvl, "args", args);
@@ -326,12 +333,10 @@
/*
* This function will be used by all functions accepting
- * a single gzFile, and returning an int.
+ * a single gzFile.
*/
int
-zcapcmd_simplecommand(file, c, command)
- gzFile file;
- int c;
+zcapcmd_simplecommand(gzFile file, int command)
{
nvlist_t *nvl, *args, *result;
@@ -341,10 +346,10 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", command);
- nvlist_add_binary(args, "file", file, sizeof(gzFile_s));
+ nvlist_add_binary(args, "file", file, gzFilesize);
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
@@ -354,10 +359,8 @@
return(ret);
}
-int
-zcapcmd_gzerror(file, errnum)
- gzFile file;
- int *errnum;
+char *
+zcapcmd_gzerror(gzFile file, int *errnum)
{
nvlist_t *nvl, *args, *result;
@@ -367,10 +370,10 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_GZPUTC);
- nvlist_add_binary(args, "file", file, sizeof(gzFile_s));
+ nvlist_add_binary(args, "file", file, gzFilesize);
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
@@ -383,10 +386,7 @@
}
uLong
-zcapcmd_adler32(adler, buf, len)
- uLong adler;
- const Bytef *buf;
- uInt len;
+zcapcmd_adler32(uLong adler, const Bytef *buf, uInt len)
{
nvlist_t *nvl, *args, *result;
uLong ret;
@@ -396,11 +396,11 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_ADLER32);
nvlist_add_number(args, "adler", adler);
- nvlist_add_binary(args, "buf", *buf, len);
+ nvlist_add_binary(args, "buf", buf, len);
nvlist_add_number(args, "len", len);
nvlist_add_nvlist(nvl, "args", args);
@@ -412,10 +412,7 @@
}
uLong
-zcapcmd_adler32_combine( adler1, adler2, len2 )
- uLong adler1;
- uLong adler2;
- z_off_t len2
+zcapcmd_adler32_combine(uLong adler1, uLong adler2, z_off_t len2 )
{
nvlist_t *nvl, *args, *result;
uLong ret;
@@ -426,7 +423,7 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_ADLER32_COMBINE);
nvlist_add_number(args, "adler2", adler2);
@@ -442,10 +439,7 @@
}
uLong
-zcapcmd_crc32(crc, buf, len)
- uLong crc;
- const Bytef *buf;
- uInt len;
+zcapcmd_crc32(uLong crc, const Bytef *buf, uInt len)
{
nvlist_t *nvl, *args, *result;
uLong ret;
@@ -455,11 +449,11 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_CRC32);
nvlist_add_number(args, "crc", crc);
- nvlist_add_binary(args, "buf", *buf, len);
+ nvlist_add_binary(args, "buf", buf, len);
nvlist_add_number(args, "len", len);
nvlist_add_nvlist(nvl, "args", args);
@@ -471,10 +465,7 @@
}
uLong
-zcapcmd_crc32_combine( crc1, crc2, len2 )
- uLong crc1;
- uLong crc2;
- z_off64_t len2;
+zcapcmd_crc32_combine(uLong crc1, uLong crc2, z_off64_t len2)
{
nvlist_t *nvl, *args, *result;
uLong ret;
@@ -485,7 +476,7 @@
if( (args = nvlist_create(0)) == NULL ||
(nvl = nvlist_create(0)) == NULL ) {
perror("nvlist_create");
- return (NULL);
+ return(0);
}
nvlist_add_number(nvl, "command", ZCAPCMD_CRC32_COMBINE);
nvlist_add_number(args, "crc1", crc1);
@@ -494,7 +485,7 @@
nvlist_add_nvlist(nvl, "args", args);
result = sendCommand(nvl);
- ret = nvlist_take_number(result, "result")
+ ret = nvlist_take_number(result, "result");
nvlist_destroy(result);
return(ret);
}
\ No newline at end of file
Modified: soc2013/dpl/head/lib/libzcap/compress.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/compress.c Thu Aug 8 17:21:59 2013 (r255683)
+++ soc2013/dpl/head/lib/libzcap/compress.c Thu Aug 8 18:26:19 2013 (r255684)
@@ -72,8 +72,7 @@
If the default memLevel or windowBits for deflateInit() is changed, then
this function needs to be updated.
*/
-uLong zcapcmd_compressBound(uLong);
-
+extern uLong zcapcmd_compressBound(uLong);
uLong ZEXPORT compressBound (sourceLen)
uLong sourceLen;
{
Modified: soc2013/dpl/head/lib/libzcap/crc32.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/crc32.c Thu Aug 8 17:21:59 2013 (r255683)
+++ soc2013/dpl/head/lib/libzcap/crc32.c Thu Aug 8 18:26:19 2013 (r255684)
@@ -201,7 +201,7 @@
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
/* ========================================================================= */
-uLong zcapcmd_crc32();
+extern uLong zcapcmd_crc32();
unsigned long ZEXPORT crc32(crc, buf, len)
unsigned long crc;
const unsigned char FAR *buf;
@@ -210,9 +210,9 @@
if (buf == Z_NULL) return 0UL;
/* Send packets of 100kb size at most. */
- if ((sizeof(*buf)*len) > (100*1024)) {
- while( (len -= (100*1024)) > 0) {
- buf += (100*1024)/sizeof(*buf);
+ if ((sizeof(*buf)*len) > (5*1024)) {
+ while( (len -= (5*1024)) > 0) {
+ buf += (5*1024)/sizeof(*buf);
crc = zcapcmd_crc32(crc, buf, len);
}
} else {
@@ -338,7 +338,7 @@
}
/* ========================================================================= */
-uLong zcapcmd_crc32_combine();
+extern uLong zcapcmd_crc32_combine();
local uLong crc32_combine_(crc1, crc2, len2)
uLong crc1;
uLong crc2;
Modified: soc2013/dpl/head/lib/libzcap/gzlib.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/gzlib.c Thu Aug 8 17:21:59 2013 (r255683)
+++ soc2013/dpl/head/lib/libzcap/gzlib.c Thu Aug 8 18:26:19 2013 (r255684)
@@ -7,6 +7,7 @@
#include "gzguts.h"
#include "zutil.h"
+#include "commands.h"
#if defined(_WIN32) && !defined(__BORLANDC__)
# define LSEEK _lseeki64
@@ -276,8 +277,8 @@
const char *mode;
{
int oflag = 0;
- for( int i = 0; i < strlen(mode); ++i){
- switch (mode[i]){
+ while(*mode) {
+ switch (*mode){
#ifndef NO_GZCOMPRESS
case('w'):
oflag |= O_WRONLY|O_CREAT|O_TRUNC;
@@ -306,6 +307,7 @@
default:
;
}
+ ++mode;
}
#ifdef O_LARGEFILE
oflag |= O_LARGEFILE;
@@ -322,7 +324,7 @@
const char *path;
const char *mode;
{
- return gzopen(path, -1, mode);
+ return gzopen(path, mode);
}
/* -- see zlib.h -- */
@@ -331,19 +333,7 @@
int fd;
const char *mode;
{
- char *path; /* identifier for error messages */
- gzFile gz;
-
- if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL)
- return NULL;
-#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
- snprintf(path, 7 + 3 * sizeof(int), "<fd:%d>", fd); /* for debugging */
-#else
- sprintf(path, "<fd:%d>", fd); /* for debugging */
-#endif
- gz = zcapcmd_gzopen(path, fd, mode);
- free(path);
- return gz;
+ return zcapcmd_gzopen(fd, mode);
}
/* -- see zlib.h -- */
@@ -366,103 +356,21 @@
}
/* -- see zlib.h -- */
+extern int zcapcmd_simplecommand();
int ZEXPORT gzrewind(file)
gzFile file;
{
- gz_statep state;
-
- /* get internal structure */
- if (file == NULL)
- return -1;
- state = (gz_statep)file;
-
- /* check that we're reading and that there's no error */
- if (state->mode != GZ_READ ||
- (state->err != Z_OK && state->err != Z_BUF_ERROR))
- return -1;
-
- /* back up and start over */
- if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
- return -1;
- gz_reset(state);
- return 0;
+ return zcapcmd_simplecommand(file, ZCAPCMD_GZREWIND);
}
/* -- see zlib.h -- */
+extern z_off_t zcapcmd_gzseek();
z_off64_t ZEXPORT gzseek64(file, offset, whence)
gzFile file;
z_off64_t offset;
int whence;
{
- unsigned n;
- z_off64_t ret;
- gz_statep state;
-
- /* get internal structure and check integrity */
- if (file == NULL)
- return -1;
- state = (gz_statep)file;
- if (state->mode != GZ_READ && state->mode != GZ_WRITE)
- return -1;
-
- /* check that there's no error */
- if (state->err != Z_OK && state->err != Z_BUF_ERROR)
- return -1;
-
- /* can only seek from start or relative to current position */
- if (whence != SEEK_SET && whence != SEEK_CUR)
- return -1;
-
- /* normalize offset to a SEEK_CUR specification */
- if (whence == SEEK_SET)
- offset -= state->x.pos;
- else if (state->seek)
- offset += state->skip;
- state->seek = 0;
-
- /* if within raw area while reading, just go there */
- if (state->mode == GZ_READ && state->how == COPY &&
- state->x.pos + offset >= 0) {
- ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR);
- if (ret == -1)
- return -1;
- state->x.have = 0;
- state->eof = 0;
- state->past = 0;
- state->seek = 0;
- gz_error(state, Z_OK, NULL);
- state->strm.avail_in = 0;
- state->x.pos += offset;
- return state->x.pos;
- }
-
- /* calculate skip amount, rewinding if needed for back seek when reading */
- if (offset < 0) {
- if (state->mode != GZ_READ) /* writing -- can't go backwards */
- return -1;
- offset += state->x.pos;
- if (offset < 0) /* before start of file! */
- return -1;
- if (gzrewind(file) == -1) /* rewind, then skip to offset */
- return -1;
- }
-
- /* if reading, skip what's in output buffer (one less gzgetc() check) */
- if (state->mode == GZ_READ) {
- n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ?
- (unsigned)offset : state->x.have;
- state->x.have -= n;
- state->x.next += n;
- state->x.pos += n;
- offset -= n;
- }
-
- /* request skip (if not zero) */
- if (offset) {
- state->seek = 1;
- state->skip = offset;
- }
- return state->x.pos + offset;
+ return zcapcmd_gzseek(file, offset, whence);
}
/* -- see zlib.h -- */
@@ -478,20 +386,11 @@
}
/* -- see zlib.h -- */
+extern int zcapcmd_simplecommand();
z_off64_t ZEXPORT gztell64(file)
gzFile file;
{
- gz_statep state;
-
- /* get internal structure and check integrity */
- if (file == NULL)
- return -1;
- state = (gz_statep)file;
- if (state->mode != GZ_READ && state->mode != GZ_WRITE)
- return -1;
-
- /* return position */
- return state->x.pos + (state->seek ? state->skip : 0);
+ return (z_off64_t)zcapcmd_simplecommand(file, ZCAPCMD_GZTELL);
}
/* -- see zlib.h -- */
@@ -505,26 +404,11 @@
}
/* -- see zlib.h -- */
+extern int zcapcmd_simplecommand();
z_off64_t ZEXPORT gzoffset64(file)
gzFile file;
{
- z_off64_t offset;
- gz_statep state;
-
- /* get internal structure and check integrity */
- if (file == NULL)
- return -1;
- state = (gz_statep)file;
- if (state->mode != GZ_READ && state->mode != GZ_WRITE)
- return -1;
-
- /* compute and return effective offset in file */
- offset = LSEEK(state->fd, 0, SEEK_CUR);
- if (offset == -1)
- return -1;
- if (state->mode == GZ_READ) /* reading */
- offset -= state->strm.avail_in; /* don't count buffered input */
- return offset;
+ return zcapcmd_simplecommand(file, ZCAPCMD_GZOFFSET);
}
/* -- see zlib.h -- */
@@ -538,62 +422,28 @@
}
/* -- see zlib.h -- */
+extern int zcapcmd_simplecommand();
int ZEXPORT gzeof(file)
gzFile file;
{
- gz_statep state;
-
- /* get internal structure and check integrity */
- if (file == NULL)
- return 0;
- state = (gz_statep)file;
- if (state->mode != GZ_READ && state->mode != GZ_WRITE)
- return 0;
-
- /* return end-of-file state */
- return state->mode == GZ_READ ? state->past : 0;
+ return zcapcmd_simplecommand(file, ZCAPCMD_GZEOF);
}
/* -- see zlib.h -- */
+extern const char * zcapcmd_gzerror();
const char * ZEXPORT gzerror(file, errnum)
gzFile file;
int *errnum;
{
- gz_statep state;
-
- /* get internal structure and check integrity */
- if (file == NULL)
- return NULL;
- state = (gz_statep)file;
- if (state->mode != GZ_READ && state->mode != GZ_WRITE)
- return NULL;
-
- /* return error information */
- if (errnum != NULL)
- *errnum = state->err;
- return state->err == Z_MEM_ERROR ? "out of memory" :
- (state->msg == NULL ? "" : state->msg);
+ return zcapcmd_gzerror(file, errnum);
}
/* -- see zlib.h -- */
+extern int zcapcmd_simplecommand();
void ZEXPORT gzclearerr(file)
gzFile file;
{
- gz_statep state;
-
- /* get internal structure and check integrity */
- if (file == NULL)
- return;
- state = (gz_statep)file;
- if (state->mode != GZ_READ && state->mode != GZ_WRITE)
- return;
-
- /* clear error and end-of-file */
- if (state->mode == GZ_READ) {
- state->eof = 0;
- state->past = 0;
- }
- gz_error(state, Z_OK, NULL);
+ zcapcmd_simplecommand(file, ZCAPCMD_GZCLEARERR);
}
/* Create an error message in allocated memory and set state->err and
Modified: soc2013/dpl/head/lib/libzcap/gzread.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/gzread.c Thu Aug 8 17:21:59 2013 (r255683)
+++ soc2013/dpl/head/lib/libzcap/gzread.c Thu Aug 8 18:26:19 2013 (r255684)
@@ -6,6 +6,7 @@
/* $FreeBSD: soc2013/dpl/head/lib/libz/gzread.c 251462 2013-05-05 06:20:49Z delphij $ */
#include "gzguts.h"
+#include "commands.h"
#include <unistd.h>
/* Local functions */
@@ -387,33 +388,11 @@
#else
# undef gzgetc
#endif
+extern int zcapcmd_simplecommand();
int ZEXPORT gzgetc(file)
gzFile file;
{
- int ret;
- unsigned char buf[1];
- gz_statep state;
-
- /* get internal structure */
- if (file == NULL)
- return -1;
- state = (gz_statep)file;
-
- /* check that we're reading and that there's no (serious) error */
- if (state->mode != GZ_READ ||
- (state->err != Z_OK && state->err != Z_BUF_ERROR))
- return -1;
-
- /* try output buffer (no need to check for skip request) */
- if (state->x.have) {
- state->x.have--;
- state->x.pos++;
- return *(state->x.next)++;
- }
-
- /* nothing there -- try gzread() */
- ret = gzread(file, buf, 1);
- return ret < 1 ? -1 : buf[0];
+ return zcapcmd_simplecommand(file, ZCAPCMD_GZGETC);
}
int ZEXPORT gzgetc_(file)
@@ -423,7 +402,7 @@
}
/* -- see zlib.h -- */
-int zcapcmd_gzungetc();
+extern int zcapcmd_gzungetc();
int ZEXPORT gzungetc(c, file)
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-soc-all
mailing list