]> git.lyx.org Git - lyx.git/blobdiff - intl/loadmsgcat.c
Fixed cursor position in minipages and small draw-fix in insettext.
[lyx.git] / intl / loadmsgcat.c
index 73e90a9190f71eada02c57f0196e7ff0a02287a4..48e807324225af3bcb6690a3b571871a8e6c69d1 100644 (file)
@@ -1,5 +1,5 @@
-/* Load needed message catalogs
-   Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Load needed message catalogs.
+   Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -44,7 +44,6 @@
 /* Rename the non ISO C functions.  This is required by the standard
    because some ISO C functions will require linking with this object
    file and the name space must not be polluted.  */
-# define fstat  __fstat
 # define open   __open
 # define close  __close
 # define read   __read
@@ -61,10 +60,12 @@ int _nl_msg_cat_cntr = 0;
 /* Load the message catalogs specified by FILENAME.  If it is no valid
    message catalog do nothing.  */
 void
+internal_function
 _nl_load_domain (domain_file)
      struct loaded_l10nfile *domain_file;
 {
   int fd;
+  size_t size;
   struct stat st;
   struct mo_file_header *data = (struct mo_file_header *) -1;
 #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
@@ -84,13 +85,18 @@ _nl_load_domain (domain_file)
     return;
 
   /* Try to open the addressed file.  */
+#ifdef CYGWIN32
+  fd = open (domain_file->filename, O_RDONLY | O_BINARY);
+#else
   fd = open (domain_file->filename, O_RDONLY);
+#endif
   if (fd == -1)
     return;
 
   /* We must know about the size of the file.  */
   if (fstat (fd, &st) != 0
-      && st.st_size < (off_t) sizeof (struct mo_file_header))
+      || (size = (size_t) st.st_size) != st.st_size
+      || size < sizeof (struct mo_file_header))
     {
       /* Something went wrong.  */
       close (fd);
@@ -101,7 +107,7 @@ _nl_load_domain (domain_file)
     || defined _LIBC
   /* Now we are ready to load the file.  If mmap() is available we try
      this first.  If not available or it failed we try to load it.  */
-  data = (struct mo_file_header *) mmap (NULL, st.st_size, PROT_READ,
+  data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,
                                         MAP_PRIVATE, fd, 0);
 
   if (data != (struct mo_file_header *) -1)
@@ -116,14 +122,14 @@ _nl_load_domain (domain_file)
      it manually.  */
   if (data == (struct mo_file_header *) -1)
     {
-      off_t to_read;
+      size_t to_read;
       char *read_ptr;
 
-      data = (struct mo_file_header *) malloc (st.st_size);
+      data = (struct mo_file_header *) malloc (size);
       if (data == NULL)
        return;
 
-      to_read = st.st_size;
+      to_read = size;
       read_ptr = (char *) data;
       do
        {
@@ -150,7 +156,7 @@ _nl_load_domain (domain_file)
 #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
     || defined _LIBC
       if (use_mmap)
-       munmap ((caddr_t) data, st.st_size);
+       munmap ((caddr_t) data, size);
       else
 #endif
        free (data);
@@ -164,6 +170,11 @@ _nl_load_domain (domain_file)
 
   domain = (struct loaded_domain *) domain_file->data;
   domain->data = (char *) data;
+#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
+    || defined _LIBC
+  domain->use_mmap = use_mmap;
+#endif
+  domain->mmap_size = size;
   domain->must_swap = data->magic != _MAGIC;
 
   /* Fill in the information about the available tables.  */
@@ -184,7 +195,7 @@ _nl_load_domain (domain_file)
 #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
     || defined _LIBC
       if (use_mmap)
-       munmap ((caddr_t) data, st.st_size);
+       munmap ((caddr_t) data, size);
       else
 #endif
        free (data);
@@ -197,3 +208,19 @@ _nl_load_domain (domain_file)
      translations invalid.  */
   ++_nl_msg_cat_cntr;
 }
+
+
+#ifdef _LIBC
+void
+internal_function
+_nl_unload_domain (domain)
+     struct loaded_domain *domain;
+{
+  if (domain->use_mmap)
+    munmap ((caddr_t) domain->data, domain->mmap_size);
+  else
+    free ((void *) domain->data);
+
+  free (domain);
+}
+#endif