pdf-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pdf-devel] Unicode path names


From: jemarch
Subject: Re: [pdf-devel] Unicode path names
Date: Thu, 22 May 2008 23:11:36 +0200
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shijō) APEL/10.6 Emacs/23.0.60 (powerpc-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO)


   Do someone know how file names are interpreted in Windows systems? The
   pdf_text module provides support conversion from Unicode to host
   encoding in Windows machines but, are file names encoded with the host
   encoding supported by pdf_text?

Specifically I am using `pdf_text_get_host' to get the host encoded
string (char*) that I then pass to `fopen'. Would the following
solution cover any local encoding setting in a Windows32 machine?

pdf_status_t
pdf_fsys_disk_open (const pdf_text_t path_name,
                    const enum pdf_fsys_file_mode_e mode,
                    pdf_fsys_file_t file)
{
  pdf_fsys_disk_file_t file_data;
  pdf_char_t mode_str[4];
  pdf_status_t ret_status;

  /* Allocate private data storage for the file */
  file_data = 
    (pdf_fsys_disk_file_t) pdf_alloc (sizeof(struct pdf_fsys_disk_file_s));
  file->data = (void *) file_data;
  

  /* Make and store a copy of the unicode file path and get the host
     encoded path */
  file_data->unicode_path = pdf_text_dup (path_name);
  if (pdf_text_get_host (&file_data->host_path,
                         &file_data->host_path_size,
                         file_data->unicode_path,
                         pdf_text_get_host_encoding ()) != PDF_OK)
    {
      /* Cleanup and report error */
      pdf_text_destroy (file_data->unicode_path);
      pdf_dealloc (file_data);

      return PDF_ERROR;
    }

  /* Build the mode string for fopen */
  pdf_fsys_disk_build_mode_string (mode, mode_str);

  /* Open the file */
  file_data->file_descriptor =
    fopen ((char *) file_data->host_path,
           (char *) mode_str);

  if (file_data->file_descriptor == NULL)
    {
      /* Cleanup and report error */
      pdf_text_destroy (file_data->unicode_path);
      pdf_dealloc (file_data->host_path);
      pdf_dealloc (file_data);
      pdf_dealloc (mode_str);

      switch (errno)
        {
        case EACCES:
        case EPERM:
        case EROFS:
#ifndef PDF_HOST_WIN32
        case ETXTBSY:
#endif /* !PDF_HOST_WIN32 */
          {
            /* Not enough permissions */
            ret_status = PDF_EBADPERMS;
            break;
          }
        case EISDIR:
        case ENAMETOOLONG:
        case ENOTDIR:
          {
            /* Invalid path name */
            ret_status = PDF_EBADNAME;
            break;
          }
        case ENOMEM:
          {
            /* Not enough memory */
            ret_status = PDF_ENOMEM;
            break;
          }
        default:
          {
            /* Other error */
            ret_status = PDF_ERROR;
            break;
          }
        }

      return ret_status;
    }

  /* All was ok */
  return PDF_OK;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]