Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/intl/loadmsgcat.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    1 /* Load needed message catalogs
    2    Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
     1/* Load needed message catalogs.
     2   Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
    33
    44   This program is free software; you can redistribute it and/or modify
     
    4545   because some ISO C functions will require linking with this object
    4646   file and the name space must not be polluted.  */
    47 # define fstat  __fstat
    4847# define open   __open
    4948# define close  __close
     
    6261   message catalog do nothing.  */
    6362void
     63internal_function
    6464_nl_load_domain (domain_file)
    6565     struct loaded_l10nfile *domain_file;
    6666{
    6767  int fd;
     68  size_t size;
    6869  struct stat st;
    6970  struct mo_file_header *data = (struct mo_file_header *) -1;
     
    9192  /* We must know about the size of the file.  */
    9293  if (fstat (fd, &st) != 0
    93       && st.st_size < (off_t) sizeof (struct mo_file_header))
     94      || (size = (size_t) st.st_size) != st.st_size
     95      || size < sizeof (struct mo_file_header))
    9496    {
    9597      /* Something went wrong.  */
     
    102104  /* Now we are ready to load the file.  If mmap() is available we try
    103105     this first.  If not available or it failed we try to load it.  */
    104   data = (struct mo_file_header *) mmap (NULL, st.st_size, PROT_READ,
     106  data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,
    105107                                         MAP_PRIVATE, fd, 0);
    106108
     
    117119  if (data == (struct mo_file_header *) -1)
    118120    {
    119       off_t to_read;
     121      size_t to_read;
    120122      char *read_ptr;
    121123
    122       data = (struct mo_file_header *) malloc (st.st_size);
     124      data = (struct mo_file_header *) malloc (size);
    123125      if (data == NULL)
    124126        return;
    125127
    126       to_read = st.st_size;
     128      to_read = size;
    127129      read_ptr = (char *) data;
    128130      do
     
    151153    || defined _LIBC
    152154      if (use_mmap)
    153         munmap ((caddr_t) data, st.st_size);
     155        munmap ((caddr_t) data, size);
    154156      else
    155157#endif
     
    165167  domain = (struct loaded_domain *) domain_file->data;
    166168  domain->data = (char *) data;
     169#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
     170    || defined _LIBC
     171  domain->use_mmap = use_mmap;
     172#endif
     173  domain->mmap_size = size;
    167174  domain->must_swap = data->magic != _MAGIC;
    168175
     
    185192    || defined _LIBC
    186193      if (use_mmap)
    187         munmap ((caddr_t) data, st.st_size);
     194        munmap ((caddr_t) data, size);
    188195      else
    189196#endif
     
    198205  ++_nl_msg_cat_cntr;
    199206}
     207
     208
     209#ifdef _LIBC
     210void
     211internal_function
     212_nl_unload_domain (domain)
     213     struct loaded_domain *domain;
     214{
     215  if (domain->use_mmap)
     216    munmap ((caddr_t) domain->data, domain->mmap_size);
     217  else
     218    free ((void *) domain->data);
     219
     220  free (domain);
     221}
     222#endif
Note: See TracChangeset for help on using the changeset viewer.