Merge branch 'sparc-dev' of ssh://scm.millennium.berkeley.edu/project/cs/radlab/src...
[akaros.git] / user / apps / parlib / run_binary.c
index 3904367..2f2e6bd 100644 (file)
@@ -40,35 +40,33 @@ void run_binary()
                printf("Error reading from console.\n");
                return;
        }
-
-       char * file_name = malloc(strlen(readline_result) + 8);
-       sprintf(file_name, "./apps/%s", readline_result);
+       char* file_name = readline_result;
+       //char * file_name = malloc(strlen(readline_result) + 8);
+       //sprintf(file_name, "./apps/%s", readline_result);
        int fd = open(file_name, O_RDONLY, 0);
+       //free(file_name);
        if(fd < 0) { fd_error(); return; };
        
-       int iters = 1;
-       binary_buf = malloc(READ_SIZE);
-       if(binary_buf == NULL) { malloc_error(); return; }
-       
+       int iters = 0;
        int total_bytes_read = 0;
-       int bytes_read = read(fd, binary_buf, READ_SIZE);
-       if(bytes_read < 0) { read_error(binary_buf, fd); return; }
+       int bytes_read = 0;
+       binary_buf = NULL;
        
-       while(bytes_read > 0) {
+       while(1) {
                total_bytes_read += bytes_read; 
                void* temp_buf = realloc(binary_buf, READ_SIZE*(++iters));
                if(temp_buf == NULL) { realloc_error(binary_buf, fd); return; } 
                binary_buf = temp_buf;
                bytes_read = read(fd, binary_buf+total_bytes_read, READ_SIZE);
                if(bytes_read < 0) { read_error(binary_buf, fd); return; }
+               if(bytes_read == 0) break;
        }
        printf("Loading Binary: %s, ROMSIZE: %d\n", readline_result, total_bytes_read);
-       ssize_t error = sys_run_binary(binary_buf, NULL, total_bytes_read);
+       ssize_t error = sys_run_binary(binary_buf, NULL, total_bytes_read, 0);
        if(error < 0) {
                fprintf(stderr, "Error: Unable to run remote binary\n");
        }
        free(binary_buf);
        close(fd);
-
 }