source: trunk/src/kmk/kmkbuiltin/solfakes.c@ 1712

Last change on this file since 1712 was 1712, checked in by bird, 17 years ago

kmk_chmod: made it build on solaris (no lchmod or ALLPERMS).

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1/* $Id: $ */
2/** @file
3 *
4 * Fake Unix stuff for Solaris.
5 *
6 * Copyright (c) 2005-2007 knut st. osmundsen <bird-kBuild-spam@anduin.net>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with This program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25
26#include <stdio.h>
27#include <stdarg.h>
28#include <stdlib.h>
29#include <sys/stat.h>
30#include "solfakes.h"
31
32
33int asprintf(char **strp, const char *fmt, ...)
34{
35 int rc;
36 va_list va;
37 va_start(va, fmt);
38 rc = vasprintf(strp, fmt, va);
39 va_end(va);
40 return rc;
41}
42
43
44int vasprintf(char **strp, const char *fmt, va_list va)
45{
46 int rc;
47 char *psz;
48 size_t cb = 1024;
49
50 *strp = NULL;
51 for (;;)
52 {
53 va_list va2;
54
55 psz = malloc(cb);
56 if (!psz)
57 return -1;
58
59#ifdef va_copy
60 va_copy(va2, va);
61 rc = snprintf(psz, cb, fmt, va2);
62 va_end(va2);
63#else
64 va2 = va;
65 rc = snprintf(psz, cb, fmt, va2);
66#endif
67 if (rc < 0 || (size_t)rc < cb)
68 break;
69 cb *= 2;
70 free(psz);
71 }
72
73 *strp = psz;
74 return rc;
75}
76
77
78
79int sol_lchmod(const char *pszPath, mode_t mode)
80{
81 /*
82 * Weed out symbolic links.
83 */
84 struct stat s;
85 if ( !lstat(pszPath, &s)
86 && S_ISLNK(s.st_mode))
87 {
88 errno = -ENOSYS;
89 return -1;
90 }
91
92 return chmod(pszPath, mode);
93}
94
Note: See TracBrowser for help on using the repository browser.