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

📄 vfsfiles.c

📁 在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LEA_4S的驱动,位置速寻算法,语音芯片ISD4004的录放音驱动,LED页面管理等等.从启动代码到操作系统的移植以及到业
💻 C
📖 第 1 页 / 共 4 页
字号:
/* FUNCTION: vftell()
 * 
 * PARAM1: VFILE * vfd
 *
 * RETURNS: 
 */

long
vftell(VFILE * vfd)
{
   /* lock the VFS */
   vfs_lock();

   if (isvfile_locked(vfd))
   {
#ifdef HT_RWVFS
      /* the caller is trying to ftell a deleted file,
         so return an error condition */
      if (vfd->file == NULL)
      {
         vfs_unlock();
         return -1;
      }
#endif   /* HT_RWVFS */

#ifdef HT_EXTDEV
      if (vfd->file->method)
      {
         struct vfroutines *  vfp   =  (struct  vfroutines*)   (vfd->file->method);
         long  rc;

         rc = vfp->r_ftell(vfd);
         vfs_unlock();
         return rc;
      }
#endif   /* HT_EXTDEV */
      /* if file has been fseeked to end, return uncompressed size.
         else return current location in compression stream */
      if (vfd->cmploc == vfd->file->data + vfd->file->comp_size)
      {
         vfs_unlock();

         return vfd->file->comp_size;
      }
      else
      {
         vfs_unlock();

         return (vfd->cmploc - vfd->file->data);
      }
   }

   vfs_unlock();

#ifdef HT_LOCALFS
   /* default to call on local system */
   return(ftell((FILE*)vfd));
#else
   return EBADF;
#endif   /* HT_LOCALFS */
}



/* FUNCTION: vgetc_locked()
 * 
 * PARAM1: VFILE * vfd
 *
 * RETURNS: 
 */

int
vgetc_locked(VFILE * vfd)
{
   int   chr;

   if (isvfile_locked(vfd))
   {
#ifdef HT_RWVFS
      /* the caller is trying to read a file that's been deleted,
         so return an error condition */
      if (vfd->file == NULL)
      {
         return EOF;
      }
#endif   /* HT_RWVFS */

#ifdef HT_EXTDEV
      if (vfd->file->method)
      {
         struct vfroutines *  vfp   =  (struct  vfroutines*)   (vfd->file->method);
         return (vfp->r_fgetc(vfd));
      }
#endif   /* HT_EXTDEV */

#ifdef HT_RWVFS
      /* a freshly created file might not have a data buffer associated
         with it yet */
      if (vfd->file->data == NULL)
         return EOF;

#endif   /* HT_RWVFS */

#ifdef HTML_COMPRESSION
      if (vfd->file->flags & VF_HTMLCOMPRESSED)
      {
         if (vfd->tag)  /* last read ended inside a tag? */
         {
            chr = *vfd->tag++;
            if (chr == '\0')  /* at end of tag? */
            {
               vfd->tag = NULL;  /* clear tag flag */
               if (vfd->cmploc >= (vfd->file->data + vfd->file->comp_size))
                  return EOF;
               else
                  chr = *vfd->cmploc++;   /* get next char from file */
            }
            else  /* got valid char from inside tag */
               return (chr);
         }
         else  /* not in a tag; get next char in file */
         {
            if (vfd->cmploc >= (vfd->file->data + vfd->file->comp_size))
               return EOF;
            else
               chr = *vfd->cmploc++;
         }
#ifdef FOREIGN_LANG_SUPPORT
         if (chr == NP_ESCAPE_CHAR )      /* escape char ? */
         {
            /* If the current char is an ESCAPE char, then
             * we are interested in the next char 
             * Then next char has HIGH-BIT-SET, and it is
             * not a HTML TAG */
            chr = *vfd->cmploc++;
         }
         else
#endif
         if (chr & 0x80)   /* compressed HTML tag? */
         {
            /* find tag and insert it as source */
            vfd->tag = (u_char*) htmltags[chr & 0x7f];
            chr = *vfd->tag++;
         }
      }
      else  /* HTML compression flag not set */
      {
#endif   /* HTML_COMPRESSION */
         /* Check to see if read has advanced to end of file */
         if (vfd->cmploc >= (vfd->file->data + vfd->file->comp_size))
            chr = EOF;
         else  /* else just get next char to return */
            chr = *(vfd->cmploc++);
#ifdef HTML_COMPRESSION
      }  /* need to close brace form if...else; */
#endif   /* HTML_COMPRESSION */

      return chr;
   }

#ifdef HT_LOCALFS
   /* default to call on local system */
   return(getc((FILE*)vfd));
#else
   dtrap("vfsfiles 3\n"); /* can this happen? */
   return EOF;
#endif   /* HT_LOCALFS */
}



/* FUNCTION: vgetc()
 * 
 * PARAM1: VFILE *vfd
 *
 * RETURNS: 
 */

int
vgetc(VFILE * vfd)
{
   int   rc;

   /* lock the VFS */
   vfs_lock();

   /* get the character */
   rc = vgetc_locked(vfd);

   /* unlock the VFS */
   vfs_unlock();
   return rc;
}




/* FUNCTION: vfslookup_locked()
 * 
 * vfn_lookup() - lookup a vfs_file entry by name. Pass file name may 
 * have path prepended and/or cgi parameters appended. Return pointer 
 * to vfs_file struct if it exists, else NULL. 
 * 
 * vfslookup_locked() should be called by functions internal to the
 * VFS that have already locked the VFS
 *
 * PARAM1: char * name
 *
 * RETURNS: 
 */

struct vfs_file * 
vfslookup_locked(char * name)
{
   struct vfs_file * vp;

#ifdef VFS_STRIPPATH
   char *   cp;

   /* If root path is prepended to name, skip past it */
   if (*name == '/' || *name == '\\')
   {
      cp = strippath(name);

      if (!cp) /* strippath coundn't match our path */
      {
         /* Files like "/hub47.gif" need to be taken care of */
         if (*name == '/' || *name == '\\')
            name++;
      }
      else
         name = cp ;
   }
#endif   /* VFS_STRIPPATH */

   /* see if there is a question mark in the file name */
   if (strchr(name,'?'))
   {
      dtrap("vfsfiles 4\n"); /* is this still allowed? */
      return NULL;
   }

   for (vp = vfsfiles; vp; vp = vp->next)    /* search vfs list for name */
   {
      if (strcmp(name, vp->name) == 0)
         return vp;
   }

   return NULL;   /* fall to here if not found in for loop */
}



/* FUNCTION: vfslookup()
 * 
 * vfslookup() should be called by code that is external to the VFS
 * (like the web server) that has not locked the VFS
 *
 * PARAM1: char * name
 *
 * RETURNS: 
 */

struct vfs_file * 
vfslookup(char * name) 
{
   struct vfs_file * vp;

#ifdef VFS_UNIT_TEST
   if (vfs_log_file_name)
      dprintf("vfslookup() passed >%s<\n",name);
#endif   /* VFS_UNIT_TEST */

   /* lock the VFS */
   vfs_lock();

   /* do the lookup */
   vp = vfslookup_locked(name);

   /* unlock the VFS */
   vfs_unlock();
   return vp;
}

#ifdef VFS_STRIPPATH



/* FUNCTION: strippath()
 * 
 * strippath() - Compares the path prepended to a passed file 
 * path/name to the http_root_path variable. If the passed file 
 * path/name matches http_root_path, it strips http_root_path from 
 * the path/name and returns the remaining path/name portion for 
 * lookup in the cfs table. 
 *
 * PARAM1: char * name
 *
 * RETURNS: Returns NULL if passed path/name does NOT 
 * have the http_root_path prepended; or on any error. 
 */

char * 
strippath(char * name)
{
   char *   path; /* pointer into system path */
   char *   ptmp; /* another pointer into path */
   char *   ntmp; /* pointer into name text */
   int   dirlen;

   ntmp = uslash(name);      /* uslash() is defined in misclib\in_utils.c */
   path = http_root_path; /* The servers root path, at least one UNIX slash */
   while (*path && *ntmp)
   {
      while (*path == '/') path++;   /* strip leading slash */
         if (*path == 0)
         break;
      /* find number of chars in this directory layer's name */
      ptmp = strchr(path, '/');   /* location of next slash in path */
      if (ptmp)
         dirlen = ptmp - path;
      else
         dirlen = strlen(path);

      while (*ntmp == '/') ntmp++;   /* strip leading slash */
         if (strncmp(ntmp, path, dirlen) == 0)
      {
         path += dirlen;
         ntmp += dirlen;
      }
      else
         return NULL;   /* didn't match */
   }
   if (*path == '\0')
   {
      while (*ntmp == '\\' || *ntmp == '/')
         ntmp++;
      return ntmp;
   }
   else
      return NULL;
}

#endif   /* VFS_STRIPPATH */



/* FUNCTION: isvfile_locked()
 * 
 * isvfile_locked() should be called by functions internal to the VFS
 * that have already locked it
 *
 * PARAM1: VFILE *vfp
 *
 * RETURNS: 
 */

int
isvfile_locked(VFILE * vfp)
{
   VFILE * vtmp;

   for (vtmp = vfiles; vtmp; vtmp = vtmp->next)
      if (vtmp == vfp)
      return TRUE;

   return FALSE;  /* passed pointer not found in list */
}



/* FUNCTION: isvfile()
 * 
 * isvfile() should be called by code that is external to the VFS
 * (like the web server) that has not locked the VFS
 *
 * PARAM1: VFILE *vfp
 *
 * RETURNS: 
 */

int
isvfile(VFILE * vfp)
{
   int   rc;

   /* lock the VFS */
   vfs_lock();

   /* do the lookup */
   rc = isvfile_locked(vfp);

   /* unlock the VFS */
   vfs_unlock();
   return rc;
}



/* FUNCTION: vferror()
 * 
 * vferror() - get last error (if any) for passed file. The type of 
 * error will vary with implementation, however 0 should always be 
 * "no error". 
 *
 * PARAM1: VFILE * vfd
 *
 * RETURNS: 
 */

int
vferror(VFILE * vfd)
{
   /* lock the VFS */
   vfs_lock();

   if (isvfile_locked(vfd))
   {
      vfs_unlock();

      return vfd->error;
   }

   vfs_unlock();

#ifdef HT_LOCALFS
   return(ferror((FILE*)vfd));
#else /* not a VFILE, and no local FS */
   return -1;  /* should this be an error? */
#endif   /* HT_LOCALFS */
}



/* FUNCTION: vclearerr()
 * 
 * PARAM1: VFILE *vfd
 *
 * RETURNS: 
 */

void vclearerr(VFILE * vfd)
{
   /* lock the VFS */
   vfs_lock();

   if (isvfile_locked(vfd))
   {
      vfs_unlock();

      vfd->error = 0;
      return;
   }

   vfs_unlock();

#ifdef HT_LOCALFS
   clearerr((FILE *) vfd);
#endif   /* HT_LOCALFS */
}

#endif   /* VFS_FILES */


⌨️ 快捷键说明

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