-
Notifications
You must be signed in to change notification settings - Fork 6
C development
TODO: work in progress
Most of the API functions return 1 if successful or -1 on error.
The close function is an exception since it returns 0 if successful or -1 on error.
More details about the return values for each API function can be found in libsmdev.h
The following examples require the following headers to be included:
#include <stdlib.h>
#include <stdio.h>
#include <libsmdev.h>
libsmdev_error_t *error = NULL;
libsmdev_handle_t *handle = NULL;
if( libsmdev_handle_initialize(&handle, &error) != 1 )
{
fprintf(stderr, "Unable to initialize handle.\n");
libsmdev_error_free(&error);
exit(EXIT_FAILURE);
}
When calling the libsmdev_handle_initialize function the handle argument must refer to NULL to allocate and initialize a handle structure. The error argument is optional and can be NULL.
The function will return 1 if successful or -1 on error. On error an the library creates an error structure except if error is NULL e.g.
libsmdev_handle_initialize(&handle, NULL);
The error structure must be freed by calling the libsmdev_error_free function.
if( libsmdev_handle_free(&handle, &error) != 1 )
{
fprintf(stderr, "Unable to free handle.\n");
libsmdev_error_free(&error);
exit(EXIT_FAILURE);
}
The function will return 1 if successful or -1 on error. File is set to NULL. The function will also close the handle if it was opened.
filename = "/dev/sda";
if( libsmdev_handle_open(handle, filename, LIBSMDEV_OPEN_READ, &error) != 1 )
{
fprintf(stderr, "Unable to open handle.\n" );
libsmdev_handle_free(&handle, NULL);
libsmdev_error_free(&error);
exit(EXIT_FAILURE);
}
libsmdev provides both narrow and wide character string functions for filenames. The wide character equivalent of the open function is libsmdev_handle_open_wide. By default libsmdev will only enable wide character string support on Windows since other operating systems have build-in support for UTF-8 narrow character strings.
To compile with wide character support add --enable-wide-character-type=yes to configure, e.g.:
./configure --enable-wide-character-type=yes
Or on Windows define WINAPI and either _UNICODE
or UNICODE
When wide character string support is enabled LIBSMDEV_HAVE_WIDE_CHARACTER_TYPE is defined in <libsmdev/features.h>
TODO describe
libsmdev allows to be compiled with file-like object support using libbfio. The libsmdev configure script will automatically detect if a compatible version of libbfio is available.
When libbfio is support is enabled LIBSMDEV_HAVE_BFIO is defined in <libsmdev/features.h>
if( libsmdev_handle_close(handle, &error) != 0 )
{
fprintf(stderr, "Unable to close handle.\n" );
libsmdev_handle_free(&handle, NULL);
libsmdev_error_free(&error);
exit(EXIT_FAILURE);
}
- libsmdev.h
- man 3 libsmdev