libgphoto2 photo camera library (libgphoto2) API 2.5.32
Loading...
Searching...
No Matches
gphoto2-file.c File Reference
#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 <unistd.h>
#include <gphoto2/gphoto2-port-log.h>
#include <gphoto2/gphoto2-port-portability.h>
#include <gphoto2/gphoto2-result.h>

Data Structures

struct  _CameraFile

Macros

#define _POSIX_SOURCE
#define _DEFAULT_SOURCE
#define _DARWIN_C_SOURCE
#define _XOPEN_SOURCE   500
#define CHECK_RESULT(result)
#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.
int gp_file_ref (CameraFile *file)
 Increase reference counter for CameraFile object.
int gp_file_unref (CameraFile *file)
 Decrease reference counter for CameraFile object.
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)

Detailed Description

Author
Copyright 2000 Scott Fritzinger
Note
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
This file contains internal functions. Use of these functions from external software modules is considered deprecated.

Macro Definition Documentation

◆ CHECK_RESULT

#define CHECK_RESULT ( result)
Value:
{int r = (result); if (r < 0) return (r);}

Function Documentation

◆ gp_file_adjust_name_for_mime_type()

int gp_file_adjust_name_for_mime_type ( CameraFile * file)
Parameters
filea CameraFile
Returns
a gphoto2 error code.

References GP_OK.

Referenced by gp_filesystem_get_file().

◆ gp_file_append()

int gp_file_append ( CameraFile * file,
const char * data,
unsigned long int size )
Parameters
filea CameraFile
data
size
Returns
a gphoto2 error code.

References GP_ERROR, GP_ERROR_IO_WRITE, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_HANDLER, GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.

◆ gp_file_clean()

int gp_file_clean ( CameraFile * file)
Parameters
filea CameraFile
Returns
a gphoto2 error code.

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().

◆ gp_file_copy()

int gp_file_copy ( CameraFile * destination,
CameraFile * source )

◆ gp_file_detect_mime_type()

int gp_file_detect_mime_type ( CameraFile * file)
Parameters
filea CameraFile
Returns
a gphoto2 error code.

References GP_ERROR_IO_READ, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_MEMORY, gp_file_set_mime_type(), and GP_OK.

◆ gp_file_free()

int gp_file_free ( CameraFile * file)

descruct a CameraFile object.

Parameters
filea CameraFile
Returns
a gphoto2 error code.

References GP_FILE_ACCESSTYPE_FD, gp_file_clean(), and GP_OK.

Referenced by gp_file_unref().

◆ gp_file_get_data_and_size()

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.

Parameters
filea CameraFile
data
size
Returns
a gphoto2 error code.

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.

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_read_file(), and gp_filesystem_set_file_noop().

◆ gp_file_get_mime_type()

int gp_file_get_mime_type ( CameraFile * file,
const char ** mime_type )
Parameters
filea CameraFile
mime_typea pointer to a MIME type string
Returns
a gphoto2 error code.

References GP_OK.

Referenced by gp_camera_file_get_info().

◆ gp_file_get_mtime()

int gp_file_get_mtime ( CameraFile * file,
time_t * mtime )
Parameters
filea CameraFile
mtime
Returns
a gphoto2 error code.

References GP_OK.

Referenced by gp_filesystem_set_file_noop().

◆ gp_file_get_name()

int gp_file_get_name ( CameraFile * file,
const char ** name )
Parameters
filea CameraFile
namea pointer to a name string
Returns
a gphoto2 error code.

References GP_OK.

◆ gp_file_get_name_by_type()

int gp_file_get_name_by_type ( CameraFile * file,
const char * basename,
CameraFileType type,
char ** newname )
Parameters
filea CameraFile
basenamethe basename of the file
typethe gphoto type of the file
newnamethe new name generated
Returns
a gphoto2 error code.

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.

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, and GP_OK.

Referenced by gp_camera_capture_preview().

◆ gp_file_new()

int gp_file_new ( CameraFile ** file)

Create new CameraFile object.

Parameters
filea pointer to a CameraFile
Returns
a gphoto2 error code.

References GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.

Referenced by gp_camera_file_get_info(), gp_filesystem_get_file(), and gp_filesystem_read_file().

◆ gp_file_new_from_fd()

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.

Parameters
filea pointer to a CameraFile
fda UNIX filedescriptor
Returns
a gphoto2 error code.

References GP_FILE_ACCESSTYPE_FD, and GP_OK.

◆ gp_file_new_from_handler()

int gp_file_new_from_handler ( CameraFile ** file,
CameraFileHandler * handler,
void * private )

Create new CameraFile object using a programmatic handler.

Parameters
filea pointer to a CameraFile
handlera #CameraFileHandler
privatea private pointer for frontend use
Returns
a gphoto2 error code.

References GP_FILE_ACCESSTYPE_HANDLER, and GP_OK.

◆ gp_file_open()

int gp_file_open ( CameraFile * file,
const char * filename )
Parameters
filea CameraFile
filename
Returns
a gphoto2 error code.

References GP_ERROR, GP_ERROR_NO_MEMORY, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_MEMORY, gp_file_clean(), and GP_OK.

◆ gp_file_ref()

int gp_file_ref ( CameraFile * file)

Increase reference counter for CameraFile object.

Parameters
filea CameraFile
Returns
a gphoto2 error code.

References GP_OK.

Referenced by gp_filesystem_set_file_noop().

◆ gp_file_save()

int gp_file_save ( CameraFile * file,
const char * filename )
Parameters
filea CameraFile
filename
Returns
a gphoto2 error code.

References GP_ERROR, GP_ERROR_IO, GP_ERROR_IO_READ, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.

◆ gp_file_set_data_and_size()

int gp_file_set_data_and_size ( CameraFile * file,
char * data,
unsigned long int size )
Parameters
filea CameraFile
data
size
Returns
a gphoto2 error code.

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().

◆ gp_file_set_mime_type()

int gp_file_set_mime_type ( CameraFile * file,
const char * mime_type )
Parameters
filea CameraFile
mime_typea MIME type string
Returns
a gphoto2 error code.

References GP_OK.

Referenced by gp_file_detect_mime_type(), and gp_filesystem_get_file().

◆ gp_file_set_mtime()

int gp_file_set_mtime ( CameraFile * file,
time_t mtime )
Parameters
filea CameraFile
mtime
Returns
a gphoto2 error code.

References GP_OK.

Referenced by gp_filesystem_set_file_noop().

◆ gp_file_set_name()

int gp_file_set_name ( CameraFile * file,
const char * name )
Parameters
filea CameraFile
namea pointer to a MIME type string
Returns
a gphoto2 error code.

References GP_OK.

Referenced by gp_camera_capture_preview(), and gp_filesystem_get_file().

◆ gp_file_slurp()

int gp_file_slurp ( CameraFile * file,
char * data,
size_t size,
size_t * readlen )
Parameters
filea CameraFile
data
size
Returns
a gphoto2 error code.

Internal.

References GP_ERROR, GP_ERROR_IO_READ, GP_FILE_ACCESSTYPE_FD, GP_FILE_ACCESSTYPE_HANDLER, GP_FILE_ACCESSTYPE_MEMORY, and GP_OK.

◆ gp_file_unref()

int gp_file_unref ( CameraFile * file)

Decrease reference counter for CameraFile object.

Parameters
filea CameraFile
Returns
a gphoto2 error code.

References gp_file_free(), and GP_OK.

Referenced by gp_camera_file_get_info(), gp_filesystem_get_file(), gp_filesystem_read_file(), and gp_filesystem_set_file_noop().