[2019] | 1 | /* $Id: solfakes.c 2901 2016-09-09 15:10:24Z bird $ */
|
---|
[813] | 2 | /** @file
|
---|
| 3 | * Fake Unix stuff for Solaris.
|
---|
[2019] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[2413] | 7 | * Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
|
---|
[813] | 8 | *
|
---|
[2019] | 9 | * This file is part of kBuild.
|
---|
[813] | 10 | *
|
---|
[2019] | 11 | * kBuild is free software; you can redistribute it and/or modify
|
---|
[813] | 12 | * it under the terms of the GNU General Public License as published by
|
---|
[2019] | 13 | * the Free Software Foundation; either version 3 of the License, or
|
---|
[813] | 14 | * (at your option) any later version.
|
---|
| 15 | *
|
---|
[2019] | 16 | * kBuild is distributed in the hope that it will be useful,
|
---|
[813] | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | * GNU General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU General Public License
|
---|
[2019] | 22 | * along with kBuild. If not, see <http://www.gnu.org/licenses/>
|
---|
[813] | 23 | *
|
---|
| 24 | */
|
---|
| 25 |
|
---|
[2019] | 26 | /*******************************************************************************
|
---|
| 27 | * Header Files *
|
---|
| 28 | *******************************************************************************/
|
---|
[2113] | 29 | #include "config.h"
|
---|
[1714] | 30 | #include <errno.h>
|
---|
[813] | 31 | #include <stdio.h>
|
---|
| 32 | #include <stdarg.h>
|
---|
[960] | 33 | #include <stdlib.h>
|
---|
[1712] | 34 | #include <sys/stat.h>
|
---|
[813] | 35 | #include "solfakes.h"
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | int asprintf(char **strp, const char *fmt, ...)
|
---|
| 39 | {
|
---|
| 40 | int rc;
|
---|
| 41 | va_list va;
|
---|
| 42 | va_start(va, fmt);
|
---|
| 43 | rc = vasprintf(strp, fmt, va);
|
---|
| 44 | va_end(va);
|
---|
| 45 | return rc;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | int vasprintf(char **strp, const char *fmt, va_list va)
|
---|
| 50 | {
|
---|
| 51 | int rc;
|
---|
| 52 | char *psz;
|
---|
| 53 | size_t cb = 1024;
|
---|
| 54 |
|
---|
| 55 | *strp = NULL;
|
---|
| 56 | for (;;)
|
---|
| 57 | {
|
---|
| 58 | va_list va2;
|
---|
| 59 |
|
---|
| 60 | psz = malloc(cb);
|
---|
| 61 | if (!psz)
|
---|
| 62 | return -1;
|
---|
| 63 |
|
---|
| 64 | #ifdef va_copy
|
---|
| 65 | va_copy(va2, va);
|
---|
[2901] | 66 | rc = vsnprintf(psz, cb, fmt, va2);
|
---|
[1246] | 67 | va_end(va2);
|
---|
[813] | 68 | #else
|
---|
| 69 | va2 = va;
|
---|
[2901] | 70 | rc = vsnprintf(psz, cb, fmt, va2);
|
---|
[813] | 71 | #endif
|
---|
| 72 | if (rc < 0 || (size_t)rc < cb)
|
---|
| 73 | break;
|
---|
| 74 | cb *= 2;
|
---|
| 75 | free(psz);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | *strp = psz;
|
---|
| 79 | return rc;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[1711] | 82 |
|
---|
| 83 |
|
---|
| 84 | int sol_lchmod(const char *pszPath, mode_t mode)
|
---|
| 85 | {
|
---|
| 86 | /*
|
---|
| 87 | * Weed out symbolic links.
|
---|
| 88 | */
|
---|
| 89 | struct stat s;
|
---|
| 90 | if ( !lstat(pszPath, &s)
|
---|
| 91 | && S_ISLNK(s.st_mode))
|
---|
| 92 | {
|
---|
| 93 | errno = -ENOSYS;
|
---|
| 94 | return -1;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | return chmod(pszPath, mode);
|
---|
| 98 | }
|
---|
| 99 |
|
---|