| 1 | /* $Id: solfakes.c 2413 2010-09-11 17:43:04Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * Fake Unix stuff for Solaris.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | * Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
|
|---|
| 8 | *
|
|---|
| 9 | * This file is part of kBuild.
|
|---|
| 10 | *
|
|---|
| 11 | * kBuild is free software; you can redistribute it and/or modify
|
|---|
| 12 | * it under the terms of the GNU General Public License as published by
|
|---|
| 13 | * the Free Software Foundation; either version 3 of the License, or
|
|---|
| 14 | * (at your option) any later version.
|
|---|
| 15 | *
|
|---|
| 16 | * kBuild is distributed in the hope that it will be useful,
|
|---|
| 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
|
|---|
| 22 | * along with kBuild. If not, see <http://www.gnu.org/licenses/>
|
|---|
| 23 | *
|
|---|
| 24 | */
|
|---|
| 25 |
|
|---|
| 26 | /*******************************************************************************
|
|---|
| 27 | * Header Files *
|
|---|
| 28 | *******************************************************************************/
|
|---|
| 29 | #include "config.h"
|
|---|
| 30 | #include <errno.h>
|
|---|
| 31 | #include <stdio.h>
|
|---|
| 32 | #include <stdarg.h>
|
|---|
| 33 | #include <stdlib.h>
|
|---|
| 34 | #include <sys/stat.h>
|
|---|
| 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);
|
|---|
| 66 | rc = snprintf(psz, cb, fmt, va2);
|
|---|
| 67 | va_end(va2);
|
|---|
| 68 | #else
|
|---|
| 69 | va2 = va;
|
|---|
| 70 | rc = snprintf(psz, cb, fmt, va2);
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|