Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3304 → Rev 3303

/branches/shell/uspace/app/bdsh/cmds/builtins/cd/cd.c
32,8 → 32,11
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#ifdef HELENOS
#include <errno.h>
 
#else
#include <sys/errno.h>
#endif
#include "util.h"
#include "errors.h"
#include "entry.h"
/branches/shell/uspace/app/bdsh/Makefile
36,7 → 36,7
SOFTINT_PREFIX = ../../lib/softint
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS += -I../../srv/kbd/include
CFLAGS += -I../../srv/kbd/include -DHELENOS
 
LIBS = $(LIBC_PREFIX)/libc.a
DEFS += -DRELEASE=\"$(RELEASE)\"
/branches/shell/uspace/app/bdsh/exec.c
40,6 → 40,12
#include <string.h>
#include <fcntl.h>
 
#ifndef HELENOS
#include <linux/limits.h>
#include <sys/errno.h>
#include <sys/wait.h>
#endif
 
#include "config.h"
#include "util.h"
#include "exec.h"
75,10 → 81,23
found = (char *)malloc(PATH_MAX);
 
/* The user has specified a full or relative path, just give it back. */
if (-1 != try_access(cmd)) {
#ifdef HELENOS
if (-1 != try_access(cmd))
#else
if (-1 != access(cmd, F_OK))
#endif
{
return (char *) cmd;
}
 
#ifdef HELENOS
path_orig = PATH;
#else
path_orig = getenv("PATH");
if (NULL == path_orig)
path_orig = PATH;
#endif
 
path_tok = cli_strdup(path_orig);
 
/* Extract the PATH env to a path[] array */
97,7 → 116,12
for (i=0; path[i]; i++) {
memset(found, 0, sizeof(found));
snprintf(found, PATH_MAX, "%s/%s", path[i], cmd);
if (-1 != try_access(found)) {
#ifdef HELENOS
if (-1 != try_access(found))
#else
if (-1 != access(found, F_OK))
#endif
{
free(path_tok);
return (char *) found;
}
109,6 → 133,7
return (char *) cmd;
}
 
#ifdef HELENOS
task_id_t try_exec(char *cmd, char **argv)
{
task_id_t tid;
130,3 → 155,74
 
return tid;
}
 
#else
int try_exec(char *cmd, char **argv)
{
char *tmp;
pid_t pid;
int status;
 
/* Copy the result of allocated 'found' */
tmp = cli_strdup(find_command(cmd));
/* free the pointer, no longer needed */
free(found);
 
if (-1 == (access(tmp, F_OK))) {
cli_error(CL_EFAIL,
"%s : No such external, modular or builtin command", tmp);
free(tmp);
return CL_EFAIL;
}
 
/* Create a child to run the program */
pid = fork();
if (pid == 0) {
execv(tmp, argv);
exit(errno);
} else if (pid > 0) {
/* Block until we get a PID (and result) */
wait(&status);
status = status / 256;
} else {
/* Could not fork, ulimit or out of memory */
cli_error(CL_ENOMEM, "Could not fork");
free(tmp);
return CL_ENOMEM;
}
 
free(tmp);
 
/* Decode any errors from execv() (these explain themselves) */
switch (status) {
case ENOTDIR:
cli_error(CL_EFAIL, "%s : No such file or directory", tmp);
status = CL_EFAIL;
break;
case EISDIR:
cli_error(CL_EFAIL, "%s : Command is a directory", tmp);
status = CL_EFAIL;
break;
case EACCES:
cli_error(CL_EPERM, "%s :", tmp);
status = CL_EFAIL;
break;
case ENOMEM:
cli_error(CL_ENOMEM, "%s :", tmp);
status = CL_EFAIL;
break;
case ENAMETOOLONG:
cli_error(CL_EFAIL, "Argument list too long");
status = CL_EFAIL;
break;
case EFAULT:
cli_error(CL_EFAIL, "Invalid argument pointer\n(please report "
"this to %s)", PACKAGE_BUGREPORT);
status = CL_EFAIL;
break;
}
 
return status;
}
 
#endif /* HELENOS */
/branches/shell/uspace/app/bdsh/input.c
32,7 → 32,10
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#ifdef HELENOS
#include <io/stream.h>
#endif
 
#include "config.h"
#include "util.h"
118,6 → 121,7
return rc;
}
 
#ifdef HELENOS
/* Borrowed from Jiri Svoboda's 'cli' uspace app */
void read_line(char *buffer, int n)
{
144,7 → 148,9
putchar('\n');
buffer[chars] = '\0';
}
#endif
 
/* This is soupy, fix me */
void get_input(cliuser_t *usr)
{
char line[INPUT_MAX];
151,7 → 157,11
size_t len = 0;
 
printf("%s", usr->prompt);
#ifdef HELENOS
read_line(line, INPUT_MAX);
#else
fgets(line, INPUT_MAX, stdin);
#endif
len = strlen(line);
/* Make sure we don't have rubbish or a C/R happy user */
if (len == 0 || line[0] == '\n')
158,8 → 168,12
return;
if (len == 1 && line[len-1] == '\n')
return;
#ifndef HELENOS
/* Null terminate line */
if (len > 0 && line[len-1] == '\n')
line[len-1] = '\0';
#endif
usr->line = cli_strdup(line);
 
return;
}
 
/branches/shell/uspace/app/bdsh/config.h
4,9 → 4,11
* ports */
 
/* Specific port work-arounds : */
#ifdef HELENOS
#define PATH_MAX 255
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 0
#endif
 
/* Work around for getenv() */
#define PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
/branches/shell/uspace/app/bdsh/scli.c
39,6 → 39,10
#include "errors.h"
#include "cmds/cmds.h"
 
#ifndef HELENOS
#include <linux/limits.h>
#endif
 
/* See scli.h */
static cliuser_t usr;
 
/branches/shell/uspace/app/bdsh/input.h
7,6 → 7,9
extern int tok_input(cliuser_t *);
extern void get_input(cliuser_t *);
extern void cli_restricted(char *);
 
#ifdef HELENOS
extern void read_line(char *, int);
#endif
 
#endif
/branches/shell/uspace/app/bdsh/exec.h
1,10 → 1,13
#ifndef EXEC_H
#define EXEC_H
 
extern char *find_command(char *);
#ifdef HELENOS
#include <task.h>
 
extern char *find_command(char *);
extern task_id_t try_exec(char *, char **);
#else
extern int try_exec(char *, char **);
#endif
extern unsigned int try_access(const char *);
 
#endif