libgphoto2 photo camera library (libgphoto2) Internals
2.5.23
|
#include "config.h"
#include <gphoto2/gphoto2-file.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <utime.h>
#include <gphoto2/gphoto2-port-log.h>
#include <gphoto2/gphoto2-port-portability.h>
#include <gphoto2/gphoto2-result.h>
Go to the source code of this file.
Data Structures | |
struct | _CameraFile |
Macros | |
#define | _POSIX_SOURCE |
#define | _DEFAULT_SOURCE |
#define | CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);} |
#define | MAX_PATH 256 |
Functions | |
int | gp_file_new (CameraFile **file) |
int | gp_file_new_from_fd (CameraFile **file, int fd) |
int | gp_file_new_from_handler (CameraFile **file, CameraFileHandler *handler, void *private) |
int | gp_file_free (CameraFile *file) |
descruct a CameraFile object. More... | |
int | gp_file_ref (CameraFile *file) |
Increase reference counter for CameraFile object. More... | |
int | gp_file_unref (CameraFile *file) |
Decrease reference counter for CameraFile object. More... | |
int | gp_file_append (CameraFile *file, const char *data, unsigned long int size) |
int | gp_file_slurp (CameraFile *file, char *data, size_t size, size_t *readlen) |
int | gp_file_set_data_and_size (CameraFile *file, char *data, unsigned long int size) |
int | gp_file_get_data_and_size (CameraFile *file, const char **data, unsigned long int *size) |
int | gp_file_save (CameraFile *file, const char *filename) |
int | gp_file_open (CameraFile *file, const char *filename) |
int | gp_file_clean (CameraFile *file) |
int | gp_file_copy (CameraFile *destination, CameraFile *source) |
int | gp_file_get_name (CameraFile *file, const char **name) |
int | gp_file_get_name_by_type (CameraFile *file, const char *basename, CameraFileType type, char **newname) |
int | gp_file_get_mime_type (CameraFile *file, const char **mime_type) |
int | gp_file_set_name (CameraFile *file, const char *name) |
int | gp_file_set_mime_type (CameraFile *file, const char *mime_type) |
int | gp_file_detect_mime_type (CameraFile *file) |
int | gp_file_adjust_name_for_mime_type (CameraFile *file) |
int | gp_file_get_mtime (CameraFile *file, time_t *mtime) |
int | gp_file_set_mtime (CameraFile *file, time_t mtime) |
Variables | |
static const char * | mime_table [] |
Definition in file gphoto2-file.c.
#define _DEFAULT_SOURCE |
Definition at line 29 of file gphoto2-file.c.
#define _POSIX_SOURCE |
Definition at line 28 of file gphoto2-file.c.
Definition at line 46 of file gphoto2-file.c.
#define MAX_PATH 256 |
Definition at line 50 of file gphoto2-file.c.
int gp_file_adjust_name_for_mime_type | ( | CameraFile * | file | ) |
file | a CameraFile |
Definition at line 1083 of file gphoto2-file.c.
References GP_MIME_AVI, GP_MIME_BMP, GP_MIME_CR2, GP_MIME_CRW, GP_MIME_JPEG, GP_MIME_NEF, GP_MIME_PGM, GP_MIME_PNG, GP_MIME_PNM, GP_MIME_PPM, GP_MIME_RAW, GP_MIME_TIFF, GP_MIME_TXT, GP_MIME_WAV, and GP_OK.
Referenced by gp_filesystem_get_file(), and gp_filesystem_get_file_impl().
int gp_file_append | ( | CameraFile * | file, |
const char * | data, | ||
unsigned long int | size | ||
) |
file | a CameraFile |
data | |
size |
Definition at line 205 of file gphoto2-file.c.
References GP_ERROR, GP_ERROR_IO_WRITE, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_HANDLER, GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.
Referenced by gpi_jpeg_write().
int gp_file_clean | ( | CameraFile * | file | ) |
file | a CameraFile |
Definition at line 699 of file gphoto2-file.c.
References GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.
Referenced by gp_camera_capture_preview(), gp_camera_file_get(), gp_file_free(), and gp_file_open().
int gp_file_copy | ( | CameraFile * | destination, |
CameraFile * | source | ||
) |
destination | a CameraFile |
source | a CameraFile |
Definition at line 729 of file gphoto2-file.c.
References GP_ERROR, GP_ERROR_IO, GP_ERROR_IO_READ, GP_ERROR_IO_WRITE, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_HANDLER, GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.
Referenced by gp_filesystem_get_file_impl().
int gp_file_detect_mime_type | ( | CameraFile * | file | ) |
file | a CameraFile |
Definition at line 1029 of file gphoto2-file.c.
References CHECK_RESULT, GP_ERROR_IO_READ, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_MEMORY, gp_file_set_mime_type(), GP_MIME_JPEG, GP_MIME_RAW, GP_MIME_TIFF, and GP_OK.
int gp_file_free | ( | CameraFile * | file | ) |
descruct a CameraFile object.
file | a CameraFile |
Definition at line 147 of file gphoto2-file.c.
References CHECK_RESULT, GP_FILE_ACCESSTYPE_FD, gp_file_clean(), and GP_OK.
Referenced by gp_file_unref().
int gp_file_get_data_and_size | ( | CameraFile * | file, |
const char ** | data, | ||
unsigned long int * | size | ||
) |
Get a pointer to the data and the file's size.
file | a CameraFile |
data | |
size |
Both data and size can be NULL and will then be ignored.
For regular CameraFiles, the pointer to data that is returned is still owned by libgphoto2 and its lifetime is the same as the #file.
For filedescriptor or handler based CameraFile types, the returned data pointer is owned by the caller and needs to be free()d to avoid memory leaks.
Definition at line 398 of file gphoto2-file.c.
References GP_ERROR, GP_ERROR_IO, GP_ERROR_IO_READ, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_HANDLER, GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.
Referenced by gp_camera_file_get_info(), gp_filesystem_get_file(), gp_filesystem_lru_free(), gp_filesystem_lru_update(), gp_filesystem_read_file(), and gp_filesystem_set_file_noop().
int gp_file_get_mime_type | ( | CameraFile * | file, |
const char ** | mime_type | ||
) |
file | a CameraFile |
mime_type | a pointer to a MIME type string |
Definition at line 979 of file gphoto2-file.c.
References GP_OK.
Referenced by gp_camera_file_get_info().
int gp_file_get_mtime | ( | CameraFile * | file, |
time_t * | mtime | ||
) |
file | a CameraFile |
mtime |
Definition at line 1130 of file gphoto2-file.c.
References GP_OK.
Referenced by gp_filesystem_set_file_noop().
int gp_file_get_name | ( | CameraFile * | file, |
const char ** | name | ||
) |
file | a CameraFile |
name | a pointer to a name string |
Definition at line 873 of file gphoto2-file.c.
References GP_OK.
int gp_file_get_name_by_type | ( | CameraFile * | file, |
const char * | basename, | ||
CameraFileType | type, | ||
char ** | newname | ||
) |
file | a CameraFile |
basename | the basename of the file |
type | the gphoto type of the file |
newname | the new name generated |
This function takes the basename and generates a filename out of it depending on the gphoto filetype and the mime type in the file. The gphoto filetype will be converted to a prefix, like thumb_ or raw_, the mimetype will replace the current suffix by a different one (if necessary).
This can be used so that saving thumbnails or metadata will not overwrite the normal files.
Definition at line 899 of file gphoto2-file.c.
References GP_FILE_TYPE_AUDIO, GP_FILE_TYPE_EXIF, GP_FILE_TYPE_METADATA, GP_FILE_TYPE_NORMAL, GP_FILE_TYPE_PREVIEW, GP_FILE_TYPE_RAW, GP_OK, and mime_table.
Referenced by gp_camera_capture_preview().
int gp_file_new | ( | CameraFile ** | file | ) |
Create new CameraFile object.
file | a pointer to a CameraFile |
Definition at line 83 of file gphoto2-file.c.
References GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.
Referenced by gp_camera_file_get_info(), gp_filesystem_get_file(), and gp_filesystem_read_file().
int gp_file_new_from_fd | ( | CameraFile ** | file, |
int | fd | ||
) |
Create new CameraFile object from a UNIX filedescriptor.
This function takes ownership of the filedescriptor and will close it when closing the CameraFile.
file | a pointer to a CameraFile |
fd | a UNIX filedescriptor |
Definition at line 105 of file gphoto2-file.c.
References GP_FILE_ACCESSTYPE_FD, and GP_OK.
int gp_file_new_from_handler | ( | CameraFile ** | file, |
CameraFileHandler * | handler, | ||
void * | private | ||
) |
Create new CameraFile object using a programmatic handler.
file | a pointer to a CameraFile |
handler | a CameraFileHandler |
private | a private pointer for frontend use |
Definition at line 126 of file gphoto2-file.c.
References GP_FILE_ACCESSTYPE_HANDLER, and GP_OK.
int gp_file_open | ( | CameraFile * | file, |
const char * | filename | ||
) |
file | a CameraFile |
filename |
Definition at line 603 of file gphoto2-file.c.
References CHECK_RESULT, GP_ERROR, GP_ERROR_NO_MEMORY, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_MEMORY, gp_file_clean(), GP_MIME_UNKNOWN, GP_OK, and mime_table.
int gp_file_ref | ( | CameraFile * | file | ) |
Increase reference counter for CameraFile object.
file | a CameraFile |
Definition at line 167 of file gphoto2-file.c.
References GP_OK.
Referenced by append_file(), and gp_filesystem_set_file_noop().
int gp_file_save | ( | CameraFile * | file, |
const char * | filename | ||
) |
file | a CameraFile |
filename |
Definition at line 486 of file gphoto2-file.c.
References GP_ERROR, GP_ERROR_IO, GP_ERROR_IO_READ, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.
int gp_file_set_data_and_size | ( | CameraFile * | file, |
char * | data, | ||
unsigned long int | size | ||
) |
file | a CameraFile |
data | |
size |
Definition at line 313 of file gphoto2-file.c.
References GP_ERROR, GP_ERROR_IO_WRITE, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_HANDLER, GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.
Referenced by gp_filesystem_get_file().
int gp_file_set_mime_type | ( | CameraFile * | file, |
const char * | mime_type | ||
) |
file | a CameraFile |
mime_type | a MIME type string |
Definition at line 1013 of file gphoto2-file.c.
References GP_OK.
Referenced by gp_file_detect_mime_type(), gp_filesystem_get_file(), and gpi_jpeg_write().
int gp_file_set_mtime | ( | CameraFile * | file, |
time_t | mtime | ||
) |
file | a CameraFile |
mtime |
Definition at line 1147 of file gphoto2-file.c.
References GP_OK.
Referenced by gp_filesystem_set_file_noop().
int gp_file_set_name | ( | CameraFile * | file, |
const char * | name | ||
) |
file | a CameraFile |
name | a pointer to a MIME type string |
Definition at line 996 of file gphoto2-file.c.
References GP_OK.
Referenced by gp_camera_capture_preview(), gp_filesystem_get_file(), gp_filesystem_get_file_impl(), and gpi_jpeg_write().
int gp_file_slurp | ( | CameraFile * | file, |
char * | data, | ||
size_t | size, | ||
size_t * | readlen | ||
) |
file | a CameraFile |
data | |
size |
Internal.
Definition at line 254 of file gphoto2-file.c.
References GP_ERROR, GP_ERROR_IO_READ, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_HANDLER, GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.
int gp_file_unref | ( | CameraFile * | file | ) |
Decrease reference counter for CameraFile object.
file | a CameraFile |
Definition at line 184 of file gphoto2-file.c.
References CHECK_RESULT, gp_file_free(), and GP_OK.
Referenced by delete_all_files(), delete_file(), gp_camera_file_get_info(), gp_filesystem_get_file(), gp_filesystem_lru_free(), gp_filesystem_read_file(), and gp_filesystem_set_file_noop().
|
static |
Definition at line 575 of file gphoto2-file.c.
Referenced by gp_file_get_name_by_type(), and gp_file_open().