ngc 1.5.0
 
Loading...
Searching...
No Matches
ngcbFile.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <glob.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/resource.h>
#include <ngc/core/ngcb.h>

Macros

#define _GNU_SOURCE
 
#define _REENTRANT
 

Functions

int ngcbLoadFile (const char *fileName, char *buffer, size_t *size, char *erms)
 
int ngcbWriteFile (const char *fileName, const char *buffer, size_t size, char *erms)
 
long int ngcbFileSize (const char *fileName, char *erms)
 
int ngcbMapFile (const char *fileName, char **buffer, size_t *size, char *erms)
 
void ngcbUnmapFile (int fd, char *buffer, size_t size)
 
ssize_t ngcbRead (int fd, void *buffer, size_t size, char *erms)
 
ssize_t ngcbWrite (int fd, const void *buffer, size_t size, char *erms)
 
const char * ngcbGetFileExt (const char *fileName)
 
void ngcbParentDir (char *path, const char *fileName)
 
const char * ngcbProcName (const char *path)
 
int ngcbMkDir (const char *path, mode_t mode, char *erms)
 
int ngcbFileExists (const char *path)
 
int ngcbIsDir (const char *path)
 
int ngcbWritePerm (const char *path)
 
int ngcbReadPerm (const char *path)
 
void ngcbExpand (char *path)
 
int ngcbPathCmp (const char *path1, const char *path2)
 
double ngcbDiskSpace (const char *path, char *erms)
 
void ngcbCleanPath (char *name)
 
int ngcbSkipFd (FILE *stream)
 
int ngcbFindIndex (const char *path, int minIndex, char *erms)
 
int ngcbWin2File (FILE *fd, const char *buffer, size_t fx, size_t fy, int bitPix, size_t sx, size_t sy, size_t nx, size_t ny, int rot, char *erms)
 
void * ngcbFileBufAlloc (size_t size, char *erms)
 
void ngcbFileBufFree (void *buffer)
 
int ngcbFdCnt (void)
 

Detailed Description

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

◆ _REENTRANT

#define _REENTRANT

Function Documentation

◆ ngcbCleanPath()

void ngcbCleanPath ( char * name)

Clean all occurrences of ./ and ../ in the path given by name.

◆ ngcbDiskSpace()

double ngcbDiskSpace ( const char * path,
char * erms )

Return the free diskspace (MBytes) in path.

◆ ngcbExpand()

void ngcbExpand ( char * path)

Expand the path in case path was relative to current working directory.

◆ ngcbFdCnt()

int ngcbFdCnt ( void )

Get number of currently open file descriptors.

◆ ngcbFileBufAlloc()

void * ngcbFileBufAlloc ( size_t size,
char * erms )

Allocate file buffer. The size is given in bytes but must be multiple of 256. The returned buffer is filled with zeros.

◆ ngcbFileBufFree()

void ngcbFileBufFree ( void * buffer)

Free file buffer.

◆ ngcbFileExists()

int ngcbFileExists ( const char * path)

Return 1 in case the path exists. Otherwise zero is returned.

◆ ngcbFileSize()

long int ngcbFileSize ( const char * fileName,
char * erms )

Return the size (bytes) of the given file. If the file does not exist or the file size could not be retrieved then the value -1 is returned.

◆ ngcbFindIndex()

int ngcbFindIndex ( const char * path,
int minIndex,
char * erms )

Searche all files in the parent directory of path, that match the pattern path*.fits, and returns the first free index in the wild-card larger than minIndex.

◆ ngcbGetFileExt()

const char * ngcbGetFileExt ( const char * fileName)

Return a pointer to a string containing the file extension (i.e. string including last '.') of fileName.

◆ ngcbIsDir()

int ngcbIsDir ( const char * path)

Return 1 in case the path is a directory. Otherwise zero is returned.

◆ ngcbLoadFile()

int ngcbLoadFile ( const char * fileName,
char * buffer,
size_t * size,
char * erms )

Read the (binary) data from the file and stores them into a buffer. A buffer of appropriate size has to be allocated by the calling instance.

◆ ngcbMapFile()

int ngcbMapFile ( const char * fileName,
char ** buffer,
size_t * size,
char * erms )

Open the file specified by fileName and map its content to a buffer. The size of the mapped buffer is computed by the function. The mapping is read-only. The function returns a file descriptor to be passed to the ngcbUnmapFile() which releases the buffer and then closes the file. In case of an error (-1) is returned and erms contains the detailed error message.

◆ ngcbMkDir()

int ngcbMkDir ( const char * path,
mode_t mode,
char * erms )

Attempt to create the directory given by the path argument. Parent directories will be created as needed. The parameter mode specifies the permissions to use. It is modified by the process's umask in the usual way: the permissions of the created directory are (mode & ~umask & 0777).

◆ ngcbParentDir()

void ngcbParentDir ( char * path,
const char * fileName )

Return in path the parent directory of the file specified by fileName.

◆ ngcbPathCmp()

int ngcbPathCmp ( const char * path1,
const char * path2 )

Return 1, if path1 and path2 refer to the same file. Otherwise zero is returned.

◆ ngcbProcName()

const char * ngcbProcName ( const char * path)

Return a pointer to a string containing the file/process name (i.e. string after last '/') of path.

◆ ngcbRead()

ssize_t ngcbRead ( int fd,
void * buffer,
size_t size,
char * erms )

Short wrapper function for socket and file-system read

◆ ngcbReadPerm()

int ngcbReadPerm ( const char * path)

Return 1 in case the path readable.

◆ ngcbSkipFd()

int ngcbSkipFd ( FILE * stream)

Skip the contents of the stream until a new-line character was read. The function returns the number of skipped characters.

◆ ngcbUnmapFile()

void ngcbUnmapFile ( int fd,
char * buffer,
size_t size )

Unmap the buffer of the given size and then close the file defined by the file descriptor fd. If the buffer is a NULL pointer or size is less or equal to zero or fd is negative then no action is taken. The function returns no value.

◆ ngcbWin2File()

int ngcbWin2File ( FILE * fd,
const char * buffer,
size_t fx,
size_t fy,
int bitPix,
size_t sx,
size_t sy,
size_t nx,
size_t ny,
int rot,
char * erms )

Cut window (sx, sy, nx, ny) from a frame buffer (dimension fx, fy) and write it directly to a FILE, which must have been opened before. bitPix specifies the number of bits per pixel. rot gives a rotation angle in degrees to rotate the data clockwise before storing to file.

◆ ngcbWrite()

ssize_t ngcbWrite ( int fd,
const void * buffer,
size_t size,
char * erms )

Short wrapper function for socket and file-system write

◆ ngcbWriteFile()

int ngcbWriteFile ( const char * fileName,
const char * buffer,
size_t size,
char * erms )

Create the file specified in fileName and writes size bytes of the buffer to the file.

◆ ngcbWritePerm()

int ngcbWritePerm ( const char * path)

Return 1 in case the path writeable.