static void getdir( struct charblob * cb, struct one_wire_query * owq ) { if ( FS_dir( getdircallback, cb, PN(owq) ) != 0 ) { CharblobClear( cb ) ; } else if ( CharblobLength(cb) == 0 ) { CharblobAddChar( '\0', cb) ; } }
static int getdir( struct charblob * cb, struct one_wire_query * owq ) { int ret = 0; if ( (ret = FS_dir( getdircallback, cb, PN(owq) )) != 0 ) { CharblobClear( cb ) ; } else if ( CharblobLength(cb) == 0 ) { CharblobAddChar( '\0', cb) ; } return ret; }
SIZE_OR_ERROR FS_get(const char *path, char **return_buffer, size_t * buffer_length) { SIZE_OR_ERROR size = 0 ; /* current buffer string length */ OWQ_allocate_struct_and_pointer( owq ) ; /* Check the parameters */ if (return_buffer == NULL) { // No buffer for read result. return -EINVAL; } if (path == NULL) { path = "/"; } *return_buffer = NULL; // default return string on error if ( BAD( OWQ_create(path, owq) ) ) { /* Can we parse the input string */ return -ENOENT; } if ( IsDir( PN(owq) ) ) { /* A directory of some kind */ struct charblob cb ; CharblobInit(&cb) ; getdir( &cb, owq ) ; size = CharblobLength(&cb) ; *return_buffer = copy_buffer( CharblobData(&cb), size ) ; CharblobClear( &cb ) ; } else { /* A regular file -- so read */ if ( GOOD(OWQ_allocate_read_buffer(owq)) ) { // make the space in the buffer size = FS_read_postparse(owq) ; *return_buffer = copy_buffer( OWQ_buffer(owq), size ) ; } } // the buffer is allocated by getdir or getval OWQ_destroy(owq); /* Check the parameters */ if (*return_buffer == NULL) { // no data. return -EINVAL; } if ( buffer_length != NULL ) { *buffer_length = size ; } return size ; }
SIZE_OR_ERROR FS_get(const char *path, char **return_buffer, size_t * buffer_length) { SIZE_OR_ERROR size = 0 ; /* current buffer string length */ OWQ_allocate_struct_and_pointer( owq ) ; /* Check the parameters */ if (return_buffer == NULL) { // No buffer supplied for read result. return -EINVAL; } if (path == NULL) { path = "/"; } *return_buffer = NULL; // default return string on error if ( BAD( OWQ_create(path, owq) ) ) { /* Can we parse the input string */ return -ENOENT; } // Check for known type. if ( (PN(owq)->selected_filetype) != NO_FILETYPE ) { // local owlib knows the type. if ( IsDir( PN(owq) ) ) { /* A directory of some kind */ struct charblob cb ; CharblobInit(&cb) ; getdir( &cb, owq ) ; size = CharblobLength(&cb) ; *return_buffer = copy_buffer( CharblobData(&cb), size ) ; CharblobClear(&cb) ; } else { /* A regular file -- so read */ if ( GOOD(OWQ_allocate_read_buffer(owq)) ) { // make the space in the buffer size = FS_read_postparse(owq) ; *return_buffer = copy_buffer( OWQ_buffer(owq), size ) ; } } } else { // local owlib doesn't know the type. struct charblob cb ; CharblobInit(&cb) ; // Try directory first. if (getdir( &cb, owq ) != -ENOTDIR) { // Is a directory. size = CharblobLength(&cb) ; *return_buffer = copy_buffer( CharblobData(&cb), size ) ; } else { // Is not a directory. Try file. if ( GOOD(OWQ_allocate_read_buffer(owq)) ) { // make the space in the buffer size = FS_read_postparse(owq) ; *return_buffer = copy_buffer( OWQ_buffer(owq), size ) ; } } CharblobClear(&cb) ; } // the buffer is allocated by getdir or getval OWQ_destroy(owq); /* Check the parameters */ if (*return_buffer == NULL) { // error return -EINVAL; } if ( buffer_length != NULL ) { // return buffer length as well *buffer_length = size ; } return size ; }