diff options
author | FreeArtMan <dos21h@gmail.com> | 2020-04-15 20:52:23 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2020-04-15 20:52:23 +0100 |
commit | ef29d288ed57250b399d6a95cf26a40d4e33794e (patch) | |
tree | 10b124d73cc6bef42fba56abdf8f65fc277bcc8e | |
parent | 6c44c2e89000444b1bdf790452fd1b92d121ed06 (diff) | |
download | ihe-ef29d288ed57250b399d6a95cf26a40d4e33794e.tar.gz ihe-ef29d288ed57250b399d6a95cf26a40d4e33794e.zip |
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | cmd/cmd_open.c | 15 | ||||
-rw-r--r-- | util.c | 33 | ||||
-rw-r--r-- | util.h | 13 |
4 files changed, 61 insertions, 4 deletions
@@ -1,8 +1,8 @@ PROJECT=ihe CC=gcc CPP=g++ -CFLAGS=-I./ -I./libbuf -Wwrite-strings -fpermissive -fno-rtti -fno-exceptions -fno-unwind-tables -SOURCES=core.c +CFLAGS=-g3 -I./ -I./libbuf -Wwrite-strings -fpermissive -fno-rtti -fno-exceptions -fno-unwind-tables -std=c11 +SOURCES=core.c util.c SOURCES+=$(wildcard cmd/*.c) OBJECTS=$(SOURCES:.c=.o) LIB_OBJECTS=libcmd/libcmd.o libterm/libterm.o h64e/core.o libbuf/libbuf.o diff --git a/cmd/cmd_open.c b/cmd/cmd_open.c index d758598..ebec8c1 100644 --- a/cmd/cmd_open.c +++ b/cmd/cmd_open.c @@ -1,5 +1,6 @@ #include "buf.h" #include "core.h" +#include "util.h" #include "libcmd/cmd.h" #include "libcmd/cmd_parse.h" @@ -16,6 +17,7 @@ int c_open( cmd_arg_t *arg ) int argc = arg->argc; char **argv = arg->argv; + int *type = arg->type; char *fname = NULL; int fret = 0; @@ -25,11 +27,20 @@ int c_open( cmd_arg_t *arg ) return -1; } - fname = argv[0]; - printf("%s\n",fname); + //fname = argv[0]; + if (type[0] == CMDT_QSTR) + { + fname = alloc_new_str(argv[0]+1); + fname[strlen(argv[0])-2] = 0x0; + } else { + fname = alloc_new_str(argv[0]); + } + + printf("fname %s\n",fname); fret = file_open_fn( g_file, fname, g_flags ); //!if failure fields could be non empty inside struct + free(fname);fname=NULL; if ( fret < 0 ) { printf("Cannot open file %s\n",fname); @@ -0,0 +1,33 @@ +#include "util.h" + +char *alloc_new_str_s(char *str, size_t size) +{ + char *ret = NULL; + + if (str == NULL) + { + return NULL; + } + + //1MB is enought + if (size > (1024*1024)) + { + return NULL; + } + + ret = malloc(size+1); //extra for 1 zero at then end + if (ret == NULL) + { + return NULL; + } + + memcpy(ret, str, size); + ret[size] = 0; //add zero at the end + + return ret; +} + +char *alloc_new_str(char *str) +{ + return alloc_new_str_s(str, strlen(str)); +} @@ -0,0 +1,13 @@ +#ifndef __UTIL_H +#define __UTIL_H + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> + +char *alloc_new_str_s(char *str, size_t size); +char *alloc_new_str(char *str); + +#endif
\ No newline at end of file |