4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Copyright (c) 1988 AT&T
43 * These functions write output files.
44 * On SVR4 and newer systems use mmap(2). On older systems (or on
45 * file systems that don't support mmap), use write(2).
50 _elf_outmap(int fd
, size_t sz
, unsigned int *pflag
)
55 * Note: Some NFS implementations do not provide from enlarging a file
56 * via ftruncate(), thus this may fail with ENOSUP. In this case the
57 * fall through to the calloc() mechanism will occur.
59 if ((!*pflag
) && (ftruncate(fd
, (off_t
)sz
) == 0) &&
60 (p
= mmap(NULL
, sz
, PROT_READ
+PROT_WRITE
,
61 MAP_SHARED
, fd
, (off_t
)0)) != (char *)-1) {
69 * If mmap fails, try calloc. Some file systems don't mmap. Note, we
70 * use calloc rather than malloc, as ld(1) assumes that the backing
71 * storage it is working with is zero filled.
73 if ((p
= (char *)calloc(1, sz
)) == 0)
74 _elf_seterr(EMEM_OUT
, errno
);
80 _elf_outsync(int fd
, char *p
, size_t sz
, unsigned int flag
)
85 if ((fd
= msync(p
, sz
, MS_ASYNC
)) == -1)
90 _elf_seterr(EIO_SYNC
, err
);
93 if ((lseek(fd
, 0L, SEEK_SET
) == 0) &&
94 (write(fd
, p
, sz
) == sz
)) {
98 _elf_seterr(EIO_WRITE
, errno
);