-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* Copyright (C) 2001 Cluster File Systems, Inc.
*
* This file is part of Lustre, http://www.sf.net/projects/lustre/
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-#include <stddef.h>
-#include <unistd.h>
-#include <sys/param.h>
-#include <assert.h>
#include <libcfs/libcfsutil.h>
static int line2args(char *line, char **argv, int maxargs)
{
- char *arg;
- int i = 0;
+ char *arg;
+ int i = 0;
- arg = strtok(line, " \t");
- if ( arg ) {
- argv[i] = arg;
- i++;
- } else
- return 0;
+ arg = strtok(line, " \t");
+ if (arg == NULL || maxargs < 1)
+ return 0;
- while( (arg = strtok(NULL, " \t")) && (i <= maxargs)) {
- argv[i] = arg;
- i++;
- }
- return i;
+ argv[i++] = arg;
+ while ((arg = strtok(NULL, " \t")) != NULL && i < maxargs)
+ argv[i++] = arg;
+ return i;
}
/* find a command -- return it if unique otherwise print alternatives */
this with strtok*/
name = skipwhitespace(name);
*next = skiptowhitespace(name);
- len = *next - name;
+ len = (int)(*next - name);
if (len == 0)
return NULL;
if ((c = fgetc(stdin)) != EOF) {
if (c == '\n')
goto out;
- *ptr++ = c;
+ *ptr++ = (char)c;
if (ptr - line >= size - 1) {
char *tmp;
line[0]='\0';
for ( i = 1 ; i < argc ; i++ ) {
- strcat(line, argv[i]);
+ if (strlen(argv[i]) > sizeof(line)-strlen(line)-1)
+ return -E2BIG;
+ strncat(line, argv[i], sizeof(line)-strlen(line)-1);
}
switch ( process(line, &next, top_level, &result, &prev) ) {