From edd131b1b988ae39899b002bda1e857eb80771d0 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Mon, 23 May 2011 18:26:02 +0000 Subject: [PATCH] Replaced some large local variables by other means in libburn/sg-freebsd-port.c --- cdrskin/cdrskin_timestamp.h | 2 +- libburn/sg-freebsd-port.c | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/cdrskin/cdrskin_timestamp.h b/cdrskin/cdrskin_timestamp.h index 31b39ae..e3fa4ba 100644 --- a/cdrskin/cdrskin_timestamp.h +++ b/cdrskin/cdrskin_timestamp.h @@ -1 +1 @@ -#define Cdrskin_timestamP "2011.05.23.174016" +#define Cdrskin_timestamP "2011.05.23.182627" diff --git a/libburn/sg-freebsd-port.c b/libburn/sg-freebsd-port.c index 16700e8..0ed62ff 100644 --- a/libburn/sg-freebsd-port.c +++ b/libburn/sg-freebsd-port.c @@ -720,11 +720,12 @@ int burn_os_stdio_capacity(char *path, off_t *bytes) { struct stat stbuf; struct statvfs vfsbuf; - char testpath[4096], *cpt; + char *testpath = NULL, *cpt; long blocks; - int open_mode = O_RDWR, fd, ret; off_t add_size = 0; + int fd, ret; + BURN_ALLOC_MEM(testpath, char, 4096); testpath[0] = 0; blocks = *bytes / 512; if (stat(path, &stbuf) == -1) { @@ -737,38 +738,52 @@ int burn_os_stdio_capacity(char *path, off_t *bytes) else *cpt = 0; if (stat(testpath, &stbuf) == -1) - return -1; + {ret = -1; goto ex;} #ifdef Libburn_if_this_was_linuX } else if(S_ISBLK(stbuf.st_mode)) { + int open_mode = O_RDWR, fd, ret; + if(burn_sg_open_o_excl) open_mode |= O_EXCL; fd = open(path, open_mode); if (fd == -1) - return -2; + {ret = -2; goto ex;} ret = ioctl(fd, BLKGETSIZE, &blocks); close(fd); if (ret == -1) - return -2; + {ret = -2; goto ex;} *bytes = ((off_t) blocks) * (off_t) 512; #endif /* Libburn_if_this_was_linuX */ + } else if(S_ISCHR(stbuf.st_mode)) { + fd = open(path, O_RDONLY); + if (fd == -1) + {ret = -2; goto ex;} + ret = ioctl(fd, DIOCGMEDIASIZE, &add_size); + close(fd); + if (ret == -1) + {ret = -2; goto ex;} + *bytes = add_size; } else if(S_ISREG(stbuf.st_mode)) { add_size = stbuf.st_blocks * (off_t) 512; strcpy(testpath, path); } else - return 0; + {ret = 0; goto ex;} if (testpath[0]) { if (statvfs(testpath, &vfsbuf) == -1) - return -2; + {ret = -2; goto ex;} *bytes = add_size + ((off_t) vfsbuf.f_frsize) * (off_t) vfsbuf.f_bavail; } - return 1; + ret = 1; +ex: + BURN_FREE_MEM(testpath); + return ret; }