⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deffilestore.c

📁 voltage 公司提供的一个开发Ibe的工具包
💻 C
📖 第 1 页 / 共 2 页
字号:
  VoltLibCtx *libCtx = (VoltLibCtx *)(prov->voltObject.libraryCtx);  unsigned char *contents = (unsigned char *)0;    VOLT_DECLARE_FNCT_LINE (fnctLine)  VOLT_DECLARE_ERROR_TYPE (errorType)    *data = (unsigned char *)0;  *dataLen = 0;  do  {    /* Get the data out of the file.     * First, how big is the file?     */    VOLT_SET_ERROR_TYPE (errorType, 0)    VOLT_SET_FNCT_LINE (fnctLine)    status = fileCtx->CtxGetFileSize (      fileCtx, fileHandle, (char *)0, &fileSize);    if (status != 0)      break;        /* Allocate the buffer to hold the contents.    */    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)    VOLT_SET_FNCT_LINE (fnctLine)    status = VT_ERROR_MEMORY;    contents = (unsigned char *)Z2Malloc (fileSize, VOLT_MEMORY_SENSITIVE);    if (contents == (unsigned char *)0)      break;        /* Get the data.    */    VOLT_SET_ERROR_TYPE (errorType, 0)    VOLT_SET_FNCT_LINE (fnctLine)    status = fileCtx->CtxReadFile (      fileCtx, fileHandle, (unsigned int)fileSize, contents, &contentsLen);    if (status != 0 && status != VT_ERROR_FILE_END_OF_FILE)      break;        *data = contents;    *dataLen = contentsLen;    status = 0;      } while (0);    /*If no error, we're done.   */  if (status == 0)    return (0);  /* If there was an error, free what was going to be the return buffer.   */  if (contents != (unsigned char *)0)    Z2Free (contents);  /* Log the error  */  VOLT_LOG_ERROR (    (VtLibCtx)libCtx, status, errorType, fnctLine,    "mIcLoadDataAlloc", (char *)0)  return (status);}int VoltGetFileListAlloc (  VoltLibCtx *libCtx,  unsigned char *directoryName,  unsigned int subdirectoriesFlag,  VtFileNameList **nameList   ){   unsigned int status;  unsigned int nameLen, dirLen;  unsigned char *path = (unsigned char *)0;  VtFileNameList *theList = (VtFileNameList *)0;  char *theArray1 = (Pointer)0;    char *theArray2 = (Pointer)0;  DIR *dir = (DIR *)0;  struct dirent *entry = (struct dirent *)0;  VtFileNameList *newNameList = (VtFileNameList *)0;    VOLT_DECLARE_ERROR_TYPE (errorType)  VOLT_DECLARE_SYSTEM_ERROR (systemError)  VOLT_DECLARE_ERROR_DESC (description)   VOLT_DECLARE_FNCT_LINE (fnctLine)  *nameList = (VtFileNameList *)0;  dirLen = Z2Strlen (directoryName);  status = 0;  do   {    /* Open the directory passed    */    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)    VOLT_SET_FNCT_LINE (fnctLine)    dir = opendir (directoryName);    if (dir == (DIR *) 0 )     {      status = 0;      if (errno == ENOENT)        break;      /* Any other error is an actual error      */      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_SYSTEM | VT_ERROR_TYPE_PRIMARY)      VOLT_SET_SYSTEM_ERROR (systemError, errno)          VOLT_SET_ERROR_DESC(description, "System function opendir failed")      break;    }        /* Build the list struct, the shell.    */      status = VT_ERROR_MEMORY;    VOLT_SET_FNCT_LINE (fnctLine)    theList = (VtFileNameList *)Z2Malloc (sizeof (VtFileNameList), 0);    if (theList == (VtFileNameList *)0)       break;       Z2Memset (theList, 0, sizeof (VtFileNameList));    /* Build an initial array of size 5.    */    status = VT_ERROR_MEMORY;    VOLT_SET_FNCT_LINE (fnctLine)    theArray1 = (char *)Z2Malloc (5 * sizeof (char *), 0);    if (theArray1 == (char *)0)            break;        Z2Memset (theArray1, 0, 5 * sizeof (char *));    theList->nameList = (char **)theArray1;    theList->listSize = 5;    theArray1 = (char *)0;        /* Keep searching for files until we find no more files.    */        while (1)    {      struct stat buf;      unsigned int len;      entry = readdir (dir);      if (entry == (struct dirent *)0)      {        VOLT_SET_FNCT_LINE (fnctLine)        status = 0;        if (errno == 0)          break;        /* Any other error is an actual error        */        VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_SYSTEM | VT_ERROR_TYPE_PRIMARY)        VOLT_SET_SYSTEM_ERROR (systemError, errno)            VOLT_SET_ERROR_DESC(description, "System function readdir failed")        break;      }      /* If the directory name is . or .. then continue      */      if (Z2Strcmp (".", entry->d_name) == 0)        goto NEXT_FILE;      if (Z2Strcmp ("..", entry->d_name) == 0)        goto NEXT_FILE;             len = Z2Strlen (entry->d_name);       VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)      VOLT_SET_FNCT_LINE (fnctLine)      status = VT_ERROR_MEMORY;      path = (unsigned char *)Z2Malloc (dirLen + len + 2, 0);      if (path == (unsigned char *)0)        break;            Z2Memcpy (path, directoryName, dirLen);      path [dirLen] = '/';      Z2Memcpy (path + dirLen + 1, entry->d_name, len + 1);            /* If the path represents a directory continue      */       VOLT_SET_FNCT_LINE (fnctLine)      if (stat (path , &buf) < 0 )       {                VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_SYSTEM | VT_ERROR_TYPE_PRIMARY)        VOLT_SET_SYSTEM_ERROR (systemError, errno)            VOLT_SET_ERROR_DESC(description, "System function stat failed")        status = VT_ERROR_FILE_ATTRIBUTES;        break;      }            if (S_ISDIR (buf.st_mode) )       {        /* If we don't want to look into subdirectories, continue.        */        if (subdirectoriesFlag == 0)          goto NEXT_FILE;        /* We want to find the files in the subdirectory        */        VOLT_SET_ERROR_TYPE (errorType, 0)        VOLT_SET_FNCT_LINE (fnctLine)        status = VoltGetFileListAlloc (libCtx, path, 1, &newNameList);        if (status != 0)          break;        /* copy the subdir list to the existing file list        */        VOLT_SET_FNCT_LINE (fnctLine)        status = VoltCopyFileList (libCtx, newNameList, theList);        if (status != 0)          break;        if (newNameList != (VtFileNameList *)0)        {          VoltFileListFree (libCtx, &newNameList);          newNameList = (VtFileNameList *)0;        }        goto NEXT_FILE;      }            /* We have a file, copy its name.       * First, do we have an empty array entry?       */      if (theList->listSize == theList->nameCount)      {        /* Add 5 more array entries.        */        VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)        VOLT_SET_FNCT_LINE (fnctLine)        status = VT_ERROR_MEMORY;        theArray2 = (char *)Z2Malloc (          (theList->listSize + 5) * sizeof (char *), 0);        if (theArray2 == (char *)0)          break;        Z2Memset (theArray2, 0, (theList->listSize + 5) * sizeof (char *));        /* Copy the old entries.        */        Z2Memcpy (          theArray2, theList->nameList, theList->nameCount * sizeof (char *));        Z2Free (theList->nameList);        theList->nameList = (char **)theArray2;        theList->listSize += 5;        theArray2 = (char *)0;      }       nameLen = Z2Strlen (path);      VOLT_SET_FNCT_LINE (fnctLine)      status = VT_ERROR_MEMORY;      theList->nameList[theList->nameCount] = (char *)Z2Malloc (nameLen + 1, 0);      if (theList->nameList[theList->nameCount] == (char *)0)         break;           Z2Memcpy (theList->nameList[theList->nameCount], path, nameLen);      theList->nameList[theList->nameCount][nameLen] = 0;      theList->nameCount++;           NEXT_FILE :      if (path != (unsigned char *)0)      {        Z2Free (path);        path = (unsigned char *)0;      }            status = 0;      } /* while */      /* Free up any data allocated      */      if (path != (unsigned char *)0)        Z2Free (path);            if (newNameList != (VtFileNameList *)0)        VoltFileListFree (libCtx, &newNameList);            if (theArray2 != (char *)0)        Z2Free (theArray2);      if (status != 0)        break;      /* Success, return theList       */      *nameList = theList;      status = 0;        } while (0);      if (dir != (DIR *) 0 )      closedir (dir);          /* If success, we're done.    */    if (status == 0)      return (0);    /* If error, free up what we allocated and log the error.    */    if (theList != (VtFileNameList *)0)      VoltFileListFree (libCtx, &theList);    VOLT_LOG_ERROR (    (VtLibCtx)libCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,    "VoltGetFileListAlloc", (char *)0)    return (status);}#endif /* VOLT_OS != VOLT_MACOSX */#endif /* VOLT_OS != VOLT_WINDOWS_32 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -