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

📄 filesys.c

📁 gcc-2.95.3 Linux下最常用的C编译器
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Add a filename and its expansion to our list. */static voidremember_info_filename (filename, expansion)     char *filename, *expansion;{  FILENAME_LIST *new;  if (names_and_files_index + 2 > names_and_files_slots)    {      int alloc_size;      names_and_files_slots += 10;      alloc_size = names_and_files_slots * sizeof (FILENAME_LIST *);      names_and_files =        (FILENAME_LIST **) xrealloc (names_and_files, alloc_size);    }  new = (FILENAME_LIST *)xmalloc (sizeof (FILENAME_LIST));  new->filename = xstrdup (filename);  new->expansion = expansion ? xstrdup (expansion) : (char *)NULL;  names_and_files[names_and_files_index++] = new;  names_and_files[names_and_files_index] = (FILENAME_LIST *)NULL;}static voidmaybe_initialize_infopath (){  if (!infopath_size)    {      infopath = (char *)        xmalloc (infopath_size = (1 + strlen (DEFAULT_INFOPATH)));      strcpy (infopath, DEFAULT_INFOPATH);    }}/* Add PATH to the list of paths found in INFOPATH.  2nd argument says   whether to put PATH at the front or end of INFOPATH. */voidinfo_add_path (path, where)     char *path;     int where;{  int len;  if (!infopath)    {      infopath = (char *)xmalloc (infopath_size = 200 + strlen (path));      infopath[0] = '\0';    }  len = strlen (path) + strlen (infopath);  if (len + 2 >= infopath_size)    infopath = (char *)xrealloc (infopath, (infopath_size += (2 * len) + 2));  if (!*infopath)    strcpy (infopath, path);  else if (where == INFOPATH_APPEND)    {      strcat (infopath, ":");      strcat (infopath, path);    }  else if (where == INFOPATH_PREPEND)    {      char *temp = xstrdup (infopath);      strcpy (infopath, path);      strcat (infopath, ":");      strcat (infopath, temp);      free (temp);    }}/* Make INFOPATH have absolutely nothing in it. */voidzap_infopath (){  if (infopath)    free (infopath);  infopath = (char *)NULL;  infopath_size = 0;}/* Read the contents of PATHNAME, returning a buffer with the contents of   that file in it, and returning the size of that buffer in FILESIZE.   FINFO is a stat struct which has already been filled in by the caller.   If the file cannot be read, return a NULL pointer. */char *filesys_read_info_file (pathname, filesize, finfo)     char *pathname;     long *filesize;     struct stat *finfo;{  long st_size;  *filesize = filesys_error_number = 0;  if (compressed_filename_p (pathname))    return (filesys_read_compressed (pathname, filesize, finfo));  else    {      int descriptor;      char *contents;      descriptor = open (pathname, O_RDONLY, 0666);      /* If the file couldn't be opened, give up. */      if (descriptor < 0)        {          filesys_error_number = errno;          return ((char *)NULL);        }      /* Try to read the contents of this file. */      st_size = (long) finfo->st_size;      contents = (char *)xmalloc (1 + st_size);      if ((read (descriptor, contents, st_size)) != st_size)        {          filesys_error_number = errno;          close (descriptor);          free (contents);          return ((char *)NULL);        }      close (descriptor);      *filesize = st_size;      return (contents);    }}/* Typically, pipe buffers are 4k. */#define BASIC_PIPE_BUFFER (4 * 1024)/* We use some large multiple of that. */#define FILESYS_PIPE_BUFFER_SIZE (16 * BASIC_PIPE_BUFFER)char *filesys_read_compressed (pathname, filesize, finfo)     char *pathname;     long *filesize;     struct stat *finfo;{  FILE *stream;  char *command, *decompressor;  char *contents = (char *)NULL;  *filesize = filesys_error_number = 0;  decompressor = filesys_decompressor_for_file (pathname);  if (!decompressor)    return ((char *)NULL);  command = (char *)xmalloc (10 + strlen (pathname) + strlen (decompressor));  sprintf (command, "%s < %s", decompressor, pathname);#if !defined (BUILDING_LIBRARY)  if (info_windows_initialized_p)    {      char *temp;      temp = (char *)xmalloc (5 + strlen (command));      sprintf (temp, "%s...", command);      message_in_echo_area ("%s", temp);      free (temp);    }#endif /* !BUILDING_LIBRARY */  stream = popen (command, "r");  free (command);  /* Read chunks from this file until there are none left to read. */  if (stream)    {      int offset, size;      char *chunk;          offset = size = 0;      chunk = (char *)xmalloc (FILESYS_PIPE_BUFFER_SIZE);      while (1)        {          int bytes_read;          bytes_read = fread (chunk, 1, FILESYS_PIPE_BUFFER_SIZE, stream);          if (bytes_read + offset >= size)            contents = (char *)xrealloc              (contents, size += (2 * FILESYS_PIPE_BUFFER_SIZE));          memcpy (contents + offset, chunk, bytes_read);          offset += bytes_read;          if (bytes_read != FILESYS_PIPE_BUFFER_SIZE)            break;        }      free (chunk);      pclose (stream);      contents = (char *)xrealloc (contents, offset + 1);      *filesize = offset;    }  else    {      filesys_error_number = errno;    }#if !defined (BUILDING_LIBARARY)  if (info_windows_initialized_p)    unmessage_in_echo_area ();#endif /* !BUILDING_LIBRARY */  return (contents);}/* Return non-zero if FILENAME belongs to a compressed file. */intcompressed_filename_p (filename)     char *filename;{  char *decompressor;  /* Find the final extension of this filename, and see if it matches one     of our known ones. */  decompressor = filesys_decompressor_for_file (filename);  if (decompressor)    return (1);  else    return (0);}/* Return the command string that would be used to decompress FILENAME. */char *filesys_decompressor_for_file (filename)     char *filename;{  register int i;  char *extension = (char *)NULL;  /* Find the final extension of FILENAME, and see if it appears in our     list of known compression extensions. */  for (i = strlen (filename) - 1; i > 0; i--)    if (filename[i] == '.')      {        extension = filename + i;        break;      }  if (!extension)    return ((char *)NULL);  for (i = 0; compress_suffixes[i].suffix; i++)    if (strcmp (extension, compress_suffixes[i].suffix) == 0)      return (compress_suffixes[i].decompressor);  return ((char *)NULL);}/* The number of the most recent file system error. */int filesys_error_number = 0;/* A function which returns a pointer to a static buffer containing   an error message for FILENAME and ERROR_NUM. */static char *errmsg_buf = (char *)NULL;static int errmsg_buf_size = 0;char *filesys_error_string (filename, error_num)     char *filename;     int error_num;{  int len;  char *result;  if (error_num == 0)    return ((char *)NULL);  result = strerror (error_num);  len = 4 + strlen (filename) + strlen (result);  if (len >= errmsg_buf_size)    errmsg_buf = (char *)xrealloc (errmsg_buf, (errmsg_buf_size = 2 + len));  sprintf (errmsg_buf, "%s: %s", filename, result);  return (errmsg_buf);}

⌨️ 快捷键说明

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