Gave up use of alloca() in favor of calloc() and free(),

because alloca.h is needed on Solaris and not available on FreeBSD.
This commit is contained in:
Thomas Schmitt 2010-07-05 19:14:47 +02:00
parent b01f017a6d
commit fe45249e9e

View File

@ -50,22 +50,8 @@ static char helptext[][80] = {
#include <fcntl.h> #include <fcntl.h>
#include <err.h> #include <err.h>
#include <limits.h> #include <limits.h>
#include <alloca.h>
#define LIBISOFS_WITHOUT_LIBBURN yes
#include "libisofs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <err.h>
#ifndef PATH_MAX #ifndef PATH_MAX
#define PATH_MAX Libisofs_default_path_maX #define PATH_MAX Libisofs_default_path_maX
#endif #endif
@ -99,7 +85,9 @@ tree_print_dir(IsoDir *dir, int level)
int i; int i;
IsoDirIter *iter; IsoDirIter *iter;
IsoNode *node; IsoNode *node;
char *sp = alloca(level * 2 + 1); char *sp;
sp = calloc(1, level * 2 + 1);
for (i = 0; i < level * 2; i += 2) { for (i = 0; i < level * 2; i += 2) {
sp[i] = '|'; sp[i] = '|';
@ -133,6 +121,7 @@ tree_print_dir(IsoDir *dir, int level)
} }
} }
iso_dir_iter_free(iter); iso_dir_iter_free(iter);
free(sp);
} }
int gesture_tree(int argc, char **argv) int gesture_tree(int argc, char **argv)
@ -437,7 +426,9 @@ iso_read_print_dir(IsoFileSource *dir, int level)
int ret, i; int ret, i;
IsoFileSource *file; IsoFileSource *file;
struct stat info; struct stat info;
char *sp = alloca(level * 2 + 1); char *sp;
sp = calloc(1, level * 2 + 1);
for (i = 0; i < level * 2; i += 2) { for (i = 0; i < level * 2; i += 2) {
sp[i] = '|'; sp[i] = '|';
@ -467,6 +458,7 @@ iso_read_print_dir(IsoFileSource *dir, int level)
if (ret < 0) { if (ret < 0) {
printf ("Can't print dir\n"); printf ("Can't print dir\n");
} }
free(sp);
} }
int gesture_iso_read(int argc, char **argv) int gesture_iso_read(int argc, char **argv)