[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pdf-devel
Subject:    Re: [pdf-devel] Unicode path names
From:       jemarch () gnu ! org
Date:       2008-05-22 21:11:36
Message-ID: 86r6but56f.wl%jemarch () gnu ! org
[Download RAW message or body]



   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;
}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic