pdisk, ofctl and yaboot
Garrett Cooper
yanefbsd at gmail.com
Sat Jun 28 20:44:08 UTC 2008
On Sat, Jun 28, 2008 at 10:38 AM, Torfinn Ingolfsen
<torfinn.ingolfsen at broadpark.no> wrote:
> On Sat, 28 Jun 2008 18:47:35 +0200
> "Niels S. Eliasen" <nse at delfi-konsult.com> wrote:
>
>> Hi Garrett
>> Downloaded the grub2... tried to run "make".. but get the following:
>>
>> > "Makefile", line 76: Missing dependency operator
>> > "Makefile", line 78: Need an operator
>> > "Makefile", line 80: Need an operator
>
> That's usually signs telling you that you need gmake (GNU make) instead
> of the BSD variant.
>
> HTH
Yeah. Grub depends on GNU make, not pmake (BSD make).
As for getline, it's only present in glibc =\:
<http://linux.die.net/man/3/getline>
However, it shouldn't be any more difficult than the included code set.
HTH,
-Garrett
PS This code needs reviewing and I'm not granting a warranty, like the
tort in the New BSD License says =).
/*
* Licensed under New BSD [3-clause] License available in FreeBSD.
*
* Author: Garrett Cooper
* Email: gcooper [at {SpamFree}] freebsd [dot] org
* Date: June 28, 2008
*
*/
#include <limits.h> /* For INT_MAX */
#include <stdio.h> /* For everything stdio (fgetc, etc). */
#include <string.h> /* malloc, free, and the usual memory suspects. */
#include <sys/types.h> /* For ssize_t */
/*
* Analog to _GNU_SOURCE -- do this to avoid confusing autoconf /
automake (I'm sure they have
* some sort of getline() detection scheme), until it can be verified
that this is fully compatible and
* doesn't accidentally break existing functionality.
*/
#if _GNU_COMPAT
#define DEFAULT_LINES 256
#define DEFAULT_LINES_INC 16
#define MAX_LINE_SIZE INT_MAX
ssize_t getline(char **, size_t*, FILE*);
/*
* @name getline
*
* @desc Gets a line up to a newline or a '\0' terminator.
*
* @param **linep - array of char** to use as placeholder for read line. NULL
* terminated. If NULL, will allocate DEFAULT_LINES+1 via
* calloc().
* @param *n - Number of chars requested to be read, then is replaced with.
* @param *fp - file descriptor to read.
*
* @pre *fp != NULL
*
* @ret ssize_t == length of str on success.
* @ret ssize_t == -1 for error
*
* @todo Fix Doxygen comments =).
* @todo Check compatibility with GNU getline().
*
*/
ssize_t
getline(char **linep, size_t *n, FILE *fp)
{
char *line_tmp;
/* Index in line_tmp */
int idx;
/* Assume FAIL until proven otherwise. */
int ret_code = -1;
if (n == NULL)
goto done;
/* XXX: *n = 0 => GNU getline compat? */
*n = 0;
/* fp cannot be NULL (segfault prone). */
if (fp == NULL)
goto done;
line_tmp = (char*) malloc(MAX_LINE_SIZE+1);
idx = 0;
/*
* Grab each char until a newline's encountered or '/0'.
*
* XXX: Tune the while conditional so that realloc's are done as necessary?
*/
do {
ch = fgetc(fp);
if (ch == '\0' || ch != '\n')
break;
*(line_tmp+idx) = ch;
idx++;
} while (idx < MAX_LINE_SIZE);
/* Include newline */
if (ch == '\n') {
*(line_tmp+idx) = '\n'
idx++;
}
*(line_tmp+idx) = '\0';
/*
* malloc a new char** area for linep because it's NULL. Make sure
that there are +1 lines
* so a NULL can be stored there.
*/
if (linep == NULL) {
linep = (char**) calloc(DEFAULT_LINES+1,*sizeof(char**));
if (linep == NULL)
goto done;
}
/*
* Increment size of linep, because we've potentially run out of play space.
*
* XXX: Tune to not increment in specific cases, lest we _will_ run
out of memory?
*/
else {
linep = (char**) realloc(linep,
(DEFAULT_LINES_INC+1)*sizeof(char**)+sizeof(linep));
/* NULL terminate linep */
*(linep+sizeof(linep)) = NULL;
}
size_t n_new = sizeof(line_tmp);
/* Don't do jack if line_tmp has 0-length. */
if (1 < n_new) {
/* Allocate a new char* for *linep because it's NULL. */
if (*linep == NULL) {
*linep = (char*) malloc(n_new);
}
/* Resize *linep to meet line_tmp's size. */
else if (*n != sizeof(line_tmp)) {
*linep = (char*) realloc(*linep, n_new);
}
/* Avoid NULL deref (segfault). */
if (*linep == NULL)
goto done;
/* Copy string */
strcpy(*linep, line_tmp);
*n = n_new;
/* Done! */
ret_code = strlen(*linep);
}
done:
/* cleanup temporary vars */
if (line_tmp != NULL)
free(line_tmp);
/* end cleanup */
return ret_code;
}
#endif
More information about the freebsd-ppc
mailing list