![]() |
![]() |
![]() |
![]() |
||||
![]() |
![]() |
![]() |
![]() |
||||
|
It illustrates the following features of the core API:
00001 /* ///////////////////////////////////////////////////////////////////////////// 00002 * File: example_c_7.c 00003 * 00004 * Purpose: C example program for the recls core library. Demonstrates: 00005 * 00006 * - stat() of current directory (via Recls_Stat()) 00007 * - combining paths (via Recls_CombinePaths()) 00008 * - elicitation of entry properties via structure members 00009 * - handling of errors and reporting of error information 00010 * 00011 * Created: 17th June 2006 00012 * Updated: 18th June 2006 00013 * 00014 * www: http://www.recls.org/ 00015 * 00016 * License: Copyright (c) 2006, Synesis Software Pty Ltd. 00017 * All rights reserved. 00018 * 00019 * (Licensed under the Synesis Software Open License) 00020 * 00021 * This source code is placed into the public domain 2006 00022 * by Synesis Software Pty Ltd. There are no restrictions 00023 * whatsoever to your use of the software. 00024 * 00025 * ////////////////////////////////////////////////////////////////////// */ 00026 00027 /* recls Header Files */ 00028 #include <recls/recls.h> 00029 00030 /* Standard C Library Files */ 00031 #include <stdio.h> /* for printf() / fprintf() */ 00032 #include <stdlib.h> /* for EXIT_SUCCESS / EXIT_FAILURE */ 00033 #include <string.h> 00034 00035 /* ///////////////////////////////////////////////////////////////////////// 00036 * Macros and definitions 00037 */ 00038 00039 #ifndef RECLS_NUM_ELEMENTS 00040 # define RECLS_NUM_ELEMENTS(x) (sizeof(x) / sizeof((x)[0])) 00041 #endif /* !RECLS_NUM_ELEMENTS */ 00042 00043 /* ////////////////////////////////////////////////////////////////////// */ 00044 00045 int main() 00046 { 00047 /* stat() the current directory */ 00048 recls_info_t current; 00049 recls_rc_t rc = Recls_Stat(".", RECLS_F_DIRECTORIES | RECLS_F_DIRECTORY_PARTS, ¤t); 00050 00051 if(RECLS_FAILED(rc)) 00052 { 00053 /* The search failed. Display the error string. */ 00054 char err[1001]; 00055 size_t n = Recls_GetErrorString(rc, &err[0], sizeof(err) - 1); 00056 00057 err[n] = '\0'; 00058 00059 fprintf(stderr, "stat of current directory failed: %s\n", err); 00060 00061 return EXIT_FAILURE; 00062 } 00063 else 00064 { 00065 const char path2[] = "abc/def/"; 00066 char combinedPath[1001]; 00067 size_t cch = Recls_CombinePaths(current->path.begin, path2, &combinedPath[0], RECLS_NUM_ELEMENTS(combinedPath)); 00068 00069 /* full path */ 00070 printf("%s combined with %s yields %.*s\n", current->path.begin, path2, (int)cch, combinedPath); 00071 00072 /* Close the current entry. */ 00073 Recls_CloseDetails(current); 00074 00075 return EXIT_SUCCESS; 00076 } 00077 } 00078 00079 /* ////////////////////////////////////////////////////////////////////// */
|
recls Library documentation © Synesis Software Pty Ltd, 2001-2006 |