Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_zip.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <zlib.h>
#include "nilorea/n_common.h"
#include "nilorea/n_log.h"
#include "nilorea/n_zip.h"
Include dependency graph for ex_zip.c:

Go to the source code of this file.

Data Structures

struct  MEMBER
 one stored member More...

Functions

static void expect_true (const char *what, int ok)
 count a failed check
static int file_is (const char *path, const unsigned char *data, size_t len)
 is a file these bytes
int main (int argc, char **argv)
 run the checks
static int process_args (int argc, char **argv)
 read -V
static void put16 (unsigned char *p, unsigned v)
 put a little endian 16 bit value
static void put32 (unsigned char *p, unsigned long v)
 put a little endian 32 bit value
static int write_zip (const char *path, const MEMBER *m, int count)
 write an archive of two members, the way every zip tool lays it out: local headers and data, the central directory, its end record

Variables

static int failures = 0
 failed checks
static int log_level = 3
 log level from -V

Data Structure Documentation

◆ MEMBER

struct MEMBER

one stored member

one member to write

Examples
ex_pth.c, and ex_zip.c.

Definition at line 130 of file ex_pth.c.

Collaboration diagram for MEMBER:
Data Fields
const unsigned char * data its bytes
size_t len how many
unsigned method 0 stored, 8 deflated
const char * name its name

Function Documentation

◆ expect_true()

void expect_true ( const char * what,
int ok )
static

count a failed check

Parameters
whatthe check
okits result

Definition at line 49 of file ex_zip.c.

References failures, LOG_ERR, LOG_INFO, and n_log.

◆ file_is()

int file_is ( const char * path,
const unsigned char * data,
size_t len )
static

is a file these bytes

Parameters
paththe file
datathe bytes
lenhow many
Returns
non-zero when it is
Examples
ex_zip.c.

Definition at line 193 of file ex_zip.c.

Referenced by main().

Here is the caller graph for this function:

◆ main()

int main ( int argc,
char ** argv )

run the checks

Parameters
argcargument count
argvarguments
Returns
0 on success

Definition at line 214 of file ex_zip.c.

References MEMBER::data, expect_true(), failures, file_is(), MEMBER::len, LOG_ERR, log_level, MEMBER::method, N_ZIP_MEMBER::method, n_zip_extract(), n_zip_find(), n_zip_find_ending(), n_zip_read(), MEMBER::name, process_args(), set_log_level(), N_ZIP_MEMBER::size, and write_zip().

Here is the call graph for this function:

◆ process_args()

int process_args ( int argc,
char ** argv )
static

read -V

Parameters
argcargument count
argvarguments
Returns
0, or -1 on a bad argument

Definition at line 62 of file ex_zip.c.

References log_level.

◆ put16()

void put16 ( unsigned char * p,
unsigned v )
static

put a little endian 16 bit value

Parameters
pwhere
vthe value

Definition at line 78 of file ex_zip.c.

◆ put32()

void put32 ( unsigned char * p,
unsigned long v )
static

put a little endian 32 bit value

Parameters
pwhere
vthe value

Definition at line 86 of file ex_zip.c.

References put16().

Here is the call graph for this function:

◆ write_zip()

int write_zip ( const char * path,
const MEMBER * m,
int count )
static

write an archive of two members, the way every zip tool lays it out: local headers and data, the central directory, its end record

Parameters
pathwhere
mthe members
counthow many
Returns
0, or -1

Definition at line 109 of file ex_zip.c.

References put16(), and put32().

Here is the call graph for this function:

Variable Documentation

◆ failures

int failures = 0
static

failed checks

Definition at line 44 of file ex_zip.c.

◆ log_level

int log_level = 3
static

log level from -V

Definition at line 42 of file ex_zip.c.