int fd;
vnode_t *vp;
int old_umask;
- char realpath[MAXPATHLEN];
+ char *realpath;
struct stat64 st;
int err;
+ realpath = umem_alloc(MAXPATHLEN, UMEM_NOFAIL);
+
/*
* If we're accessing a real disk from userland, we need to use
* the character interface to avoid caching. This is particularly
if (strncmp(path, "/dev/", 5) == 0) {
char *dsk;
fd = open64(path, O_RDONLY);
- if (fd == -1)
- return (errno);
+ if (fd == -1) {
+ err = errno;
+ free(realpath);
+ return (err);
+ }
if (fstat64(fd, &st) == -1) {
+ err = errno;
close(fd);
- return (errno);
+ free(realpath);
+ return (err);
}
close(fd);
(void) sprintf(realpath, "%s", path);
dsk + 1);
} else {
(void) sprintf(realpath, "%s", path);
- if (!(flags & FCREAT) && stat64(realpath, &st) == -1)
- return (errno);
+ if (!(flags & FCREAT) && stat64(realpath, &st) == -1) {
+ err = errno;
+ free(realpath);
+ return (err);
+ }
}
if (flags & FCREAT)
* FREAD and FWRITE to the corresponding O_RDONLY, O_WRONLY, and O_RDWR.
*/
fd = open64(realpath, flags - FREAD, mode);
+ free(realpath);
if (flags & FCREAT)
(void) umask(old_umask);
umem_free(ksid, sizeof (ksiddomain_t));
}
-/*
- * Do not change the length of the returned string; it must be freed
- * with strfree().
- */
char *
-kmem_asprintf(const char *fmt, ...)
+kmem_vasprintf(const char *fmt, va_list adx)
{
- int size;
- va_list adx;
- char *buf;
+ char *buf = NULL;
+ va_list adx_copy;
- va_start(adx, fmt);
- size = vsnprintf(NULL, 0, fmt, adx) + 1;
- va_end(adx);
+ va_copy(adx_copy, adx);
+ VERIFY(vasprintf(&buf, fmt, adx_copy) != -1);
+ va_end(adx_copy);
+
+ return (buf);
+}
- buf = kmem_alloc(size, KM_SLEEP);
+char *
+kmem_asprintf(const char *fmt, ...)
+{
+ char *buf = NULL;
+ va_list adx;
va_start(adx, fmt);
- size = vsnprintf(buf, size, fmt, adx);
+ VERIFY(vasprintf(&buf, fmt, adx) != -1);
va_end(adx);
return (buf);