dmlite 0.6
Macros | Typedefs | Functions
io.h File Reference

C wrapper for I/O interfaces. More...

#include "dmlite.h"
#include "any.h"
#include "pool.h"
#include <sys/uio.h>
#include <unistd.h>
Include dependency graph for io.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define O_INSECURE   010
 

Typedefs

typedef struct dmlite_fd dmlite_fd
 

Functions

dmlite_fddmlite_fopen (dmlite_context *context, const char *path, int flags, const dmlite_any_dict *extra,...)
 Opens a file.
 
int dmlite_fclose (dmlite_fd *fd)
 Closes a file.
 
int dmlite_fstat (dmlite_fd *fd, struct stat *buf)
 Gets information about a file descriptor.
 
int dmlite_fseek (dmlite_fd *fd, off_t offset, int whence)
 Sets the file position.
 
off_t dmlite_ftell (dmlite_fd *fd)
 Returns the cursor position.
 
ssize_t dmlite_fread (dmlite_fd *fd, void *buffer, size_t count)
 Reads from a file.
 
ssize_t dmlite_fwrite (dmlite_fd *fd, const void *buffer, size_t count)
 Writes to a file.
 
ssize_t dmlite_freadv (dmlite_fd *fd, const struct iovec *vector, size_t count)
 Reads from a file into multiple buffers.
 
ssize_t dmlite_fwritev (dmlite_fd *fd, const struct iovec *vector, size_t count)
 Reads from a file into multiple buffers.
 
ssize_t dmlite_fpread (dmlite_fd *fd, void *buffer, size_t count, off_t offset)
 Reads up to count bytes starting at the given offset. Does not change internal offset.
 
ssize_t dmlite_fpwrite (dmlite_fd *fd, const void *buffer, size_t count, off_t offset)
 Writes count bytes starting at the given offset. Does not change internal offset.
 
int dmlite_feof (dmlite_fd *fd)
 Returns 1 if EOF.
 
int dmlite_ferrno (dmlite_fd *fd)
 Returns the last errror code.
 
const char * dmlite_ferror (dmlite_fd *fd)
 Returns the last error message.
 
int dmlite_donewriting (dmlite_context *context, const dmlite_location *loc)
 Finishes a PUT.
 
int dmlite_fileno (dmlite_fd *fd)
 Returns the system file descriptor if available.
 

Detailed Description

C wrapper for I/O interfaces.

Author
Alejandro Álvarez Ayllon aalva.nosp@m.rez@.nosp@m.cern..nosp@m.ch

Macro Definition Documentation

◆ O_INSECURE

#define O_INSECURE   010

Use this flag in addition to the standard ones to skip any security check (i.e. token validation)

Typedef Documentation

◆ dmlite_fd

typedef struct dmlite_fd dmlite_fd

Handle for a file descriptor.

Function Documentation

◆ dmlite_donewriting()

int dmlite_donewriting ( dmlite_context * context,
const dmlite_location * loc )

Finishes a PUT.

Parameters
contextThe DM context.
locThe location as returned by dmlite_put.
Returns
0 on success, error code otherwise.

◆ dmlite_fclose()

int dmlite_fclose ( dmlite_fd * fd)

Closes a file.

Parameters
fdThe file descriptor as returned by dmlite_open.
Returns
0 on success, error code otherwise.

◆ dmlite_feof()

int dmlite_feof ( dmlite_fd * fd)

Returns 1 if EOF.

Parameters
fdThe file descriptor.
Returns
0 if there is more to read. 1 if EOF.

◆ dmlite_ferrno()

int dmlite_ferrno ( dmlite_fd * fd)

Returns the last errror code.

Parameters
fdThe file descriptor.
Returns
The last error code.

◆ dmlite_ferror()

const char * dmlite_ferror ( dmlite_fd * fd)

Returns the last error message.

Parameters
fdThe file descriptor.
Returns
A pointer to an internal buffer with the last error message.
Note
This buffer is specific to each file descriptor.

◆ dmlite_fileno()

int dmlite_fileno ( dmlite_fd * fd)

Returns the system file descriptor if available.

Parameters
fdThe file descriptor.
Returns
The file descriptor, -1 if it can not be retrieved.
Note
Support depends on the plugin providing the file.
Calling dmlite_fclose will close the file descriptor returned by this.

◆ dmlite_fopen()

dmlite_fd * dmlite_fopen ( dmlite_context * context,
const char * path,
int flags,
const dmlite_any_dict * extra,
... )

Opens a file.

Parameters
contextThe DM context.
pathThe path to open.
flagsSee open()
extraThe key-value pairs.
...Should be mode_t when called with O_CREAT.
Returns
An opaque handler for the file, NULL on failure.

◆ dmlite_fpread()

ssize_t dmlite_fpread ( dmlite_fd * fd,
void * buffer,
size_t count,
off_t offset )

Reads up to count bytes starting at the given offset. Does not change internal offset.

Parameters
fdFile descriptor.
bufferBuffer where to put the data.
countNumber of bytes to read.
offsetRead offset.
Returns
Number of bytes actually read on success. -1 on failure.

◆ dmlite_fpwrite()

ssize_t dmlite_fpwrite ( dmlite_fd * fd,
const void * buffer,
size_t count,
off_t offset )

Writes count bytes starting at the given offset. Does not change internal offset.

Parameters
fdFile descriptor.
bufferData to write.
countNumber of bytes to read.
offsetWrite offset.
Returns
Number of bytes actually write on success. -1 on failure.

◆ dmlite_fread()

ssize_t dmlite_fread ( dmlite_fd * fd,
void * buffer,
size_t count )

Reads from a file.

Parameters
fdThe file descriptor.
bufferWhere to put the data.
countNumber of bytes to read.
Returns
Number of bytes actually read on success. -1 on failure.

◆ dmlite_freadv()

ssize_t dmlite_freadv ( dmlite_fd * fd,
const struct iovec * vector,
size_t count )

Reads from a file into multiple buffers.

Parameters
fdThe file descriptor.
vectorArray of buffers.
countNumber of elements in the array of buffers.
Returns
Number of bytes actually read on success. -1 on failure.

◆ dmlite_fseek()

int dmlite_fseek ( dmlite_fd * fd,
off_t offset,
int whence )

Sets the file position.

Parameters
fdThe file descriptor.
offsetThe offset.
whenceSee fseek()
Returns
0 on success, error code otherwise.

◆ dmlite_fstat()

int dmlite_fstat ( dmlite_fd * fd,
struct stat * buf )

Gets information about a file descriptor.

Parameters
fdThe file descriptor.
bufWhere to put the information.
Returns
0 on success, error code otherwise.
Note
Not all plug-ins will fill all the fields, but st_size is a reasonable expectation.

◆ dmlite_ftell()

off_t dmlite_ftell ( dmlite_fd * fd)

Returns the cursor position.

Parameters
fdThe file descriptor.
Returns
The cursor position, or -1 on error.

◆ dmlite_fwrite()

ssize_t dmlite_fwrite ( dmlite_fd * fd,
const void * buffer,
size_t count )

Writes to a file.

Parameters
fdThe file descriptor.
bufferA pointer to the data.
countNumber of bytes to write.
Returns
Number of bytes actually written. -1 on failure.

◆ dmlite_fwritev()

ssize_t dmlite_fwritev ( dmlite_fd * fd,
const struct iovec * vector,
size_t count )

Reads from a file into multiple buffers.

Parameters
fdThe file descriptor.
vectorArray of buffers.
countNumber of elements in the array of buffers.
Returns
Number of bytes actually read on success. -1 on failure.