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

Go to the source code of this file.

Functions

static size_t build (unsigned char *buf, int be)
 Build a DCP shaped buffer: a name, a short, three signed rationals, two floats, and one entry pointing past the end.
static void check (const char *what, int ok)
 Count and print a failed condition.
static int list_file (const char *path)
 List the tags of a file's first directory.
int main (int argc, char **argv)
 Run the checks, or list a file given as the argument.
static void put16 (unsigned char *p, uint16_t v, int be)
 Write a 16 bit value in a byte order.
static void put32 (unsigned char *p, uint32_t v, int be)
 Write a 32 bit value in a byte order.
static void put_entry (unsigned char *e, uint16_t tag, uint16_t type, uint32_t count, uint32_t value, int be)
 Write one directory entry.
static void test_broken (void)
 Broken buffers are refused, never read out of bounds.
static void test_order (int be)
 Parse a built buffer and check every value.

Variables

static int failures = 0
 failures counted by check()

Function Documentation

◆ build()

size_t build ( unsigned char * buf,
int be )
static

Build a DCP shaped buffer: a name, a short, three signed rationals, two floats, and one entry pointing past the end.

Parameters
bufreceives it, 256 bytes
benon-zero for big endian
Returns
its length
Examples
ex_tiff.c.

Definition at line 93 of file ex_tiff.c.

References N_TIFF_MAGIC_DCP, put16(), put32(), and put_entry().

Referenced by test_broken(), and test_order().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check()

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

Count and print a failed condition.

Parameters
whatwhat was checked
okthe condition

Definition at line 47 of file ex_tiff.c.

References failures.

◆ list_file()

int list_file ( const char * path)
static

List the tags of a file's first directory.

Parameters
paththe file
Returns
0, or 1 when it cannot be read or parsed
Examples
ex_tiff.c.

Definition at line 176 of file ex_tiff.c.

References N_TIFF::big_endian, N_TIFF::count, N_TIFF_ENTRY::count, N_TIFF::entries, N_TIFF::magic, n_file_read_bounded(), n_tiff_free(), n_tiff_parse(), N_TIFF_ENTRY::tag, and N_TIFF_ENTRY::type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Run the checks, or list a file given as the argument.

-V LEVEL sets the log level, as for every example: run_tests.sh passes it, and before this it was taken for the name of a file to list.

Parameters
argcargument count
argvarguments
Returns
0 on success

Definition at line 210 of file ex_tiff.c.

References failures, list_file(), LOG_ERR, log_level, set_log_level(), test_broken(), and test_order().

Here is the call graph for this function:

◆ put16()

void put16 ( unsigned char * p,
uint16_t v,
int be )
static

Write a 16 bit value in a byte order.

Parameters
pwhere
vthe value
benon-zero for big endian
Examples
ex_tiff.c, and ex_zip.c.

Definition at line 58 of file ex_tiff.c.

Referenced by build(), put32(), put_entry(), test_broken(), and write_zip().

Here is the caller graph for this function:

◆ put32()

void put32 ( unsigned char * p,
uint32_t v,
int be )
static

Write a 32 bit value in a byte order.

Parameters
pwhere
vthe value
benon-zero for big endian
Examples
ex_tiff.c, and ex_zip.c.

Definition at line 67 of file ex_tiff.c.

Referenced by build(), put_entry(), test_broken(), and write_zip().

Here is the caller graph for this function:

◆ put_entry()

void put_entry ( unsigned char * e,
uint16_t tag,
uint16_t type,
uint32_t count,
uint32_t value,
int be )
static

Write one directory entry.

Parameters
ewhere
tagtag
typefield type
countvalue count
valuethe value itself, or the offset of the values
benon-zero for big endian
Examples
ex_tiff.c.

Definition at line 81 of file ex_tiff.c.

References put16(), put32(), and type().

Referenced by build().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_broken()

void test_broken ( void )
static

Broken buffers are refused, never read out of bounds.

Examples
ex_tiff.c.

Definition at line 158 of file ex_tiff.c.

References build(), check(), n_tiff_parse(), put16(), and put32().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_order()

void test_order ( int be)
static

Parse a built buffer and check every value.

Parameters
benon-zero for big endian
Examples
ex_tiff.c.

Definition at line 127 of file ex_tiff.c.

References N_TIFF::big_endian, build(), check(), N_TIFF::count, N_TIFF::magic, n_tiff_count(), n_tiff_find(), n_tiff_free(), n_tiff_get_ascii(), n_tiff_get_doubles(), N_TIFF_MAGIC_DCP, and n_tiff_parse().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ failures

int failures = 0
static

failures counted by check()

Definition at line 42 of file ex_tiff.c.