Esempio n. 1
0
int main(void)
{

  heap_init();

  char buffer[64];
  char startString[] = "Please write 10 characters: \n";
  char endString[] = "\nTest complete.\n";

  void *pointer = malloc(sizeof(buffer));



  syscall_write(FILEHANDLE_STDIN, startString, 30);

  syscall_read(FILEHANDLE_STDIN, buffer, 10);

  syscall_write(FILEHANDLE_STDIN, buffer, 10);

  syscall_write(FILEHANDLE_STDIN, endString, 16);

  syscall_halt();
  
  return 0;
}
Esempio n. 2
0
int main(void)
{
  int fid;
  int len = 32;  
  char buffer1[32] = "Hello this is first message";
  char buffer2[32] = "Hello second message is up";
  char buffer3[32] = "Third message coming your way";
  char buffer4[32] = "Last but not least, message four";

  fid = syscall_open("[pipe]test");
  //  printf("Fid from read is %d\n", fid);
 
  // write one time
  syscall_seek(fid,0);
  syscall_write(fid,buffer1,len);
  
  // write again
  syscall_seek(fid,0);
  syscall_write(fid,buffer2,len);

  // write again
  syscall_seek(fid,0);
  syscall_write(fid,buffer3,len);

  //try to remove the pipe 
  syscall_delete("[pipe]test");

  // write again
  syscall_seek(fid,0);
  syscall_write(fid,buffer4,len);


  return 0;
}
Esempio n. 3
0
void ps_print(uint64_t pid,char*pname){
    char str[10]= {0};
    itoa_kernel(pid,str,10);
    syscall_write(1,"PID:[",strlen_kernel("PID:["));
    syscall_write(1,str,strlen_kernel(str));
    syscall_write(1,"] TTY:pts/1 Process:[",strlen_kernel("] TTY:pts/1 Process:["));
    syscall_write(1,pname,strlen_kernel(pname));
    syscall_write(1,"]\n",2);
}
Esempio n. 4
0
int main(void)
{
  int i;
  char str[3];

  syscall_write(1, "Validprogram1: Caling 'vallidprogram2'\n",39);
  
  syscall_exec(syscall_exec(validprog));

  syscall_write(1,"That is it! Goodbye\n",20);
  syscall_exit(4);
  return 0;
}
Esempio n. 5
0
void do_syscall(TrapFrame *tf) {
   int id = tf->eax;
   switch(id) {
      case SYS_fork:  syscall_fork(tf); break;
      case SYS_exec:  syscall_exec(tf); break;
      case SYS_exit:  syscall_exit(tf); break;
      case SYS_getpid:  syscall_getpid(tf); break;
      case SYS_waitpid:  syscall_waitpid(tf); break;
      case SYS_puts1:  printk((char*)(tf->ebx)); printk("   %d\n", current->pid); break;
      case SYS_puts: syscall_puts(tf); break;
      case SYS_read_line: syscall_read_line(tf); break;
      case SYS_sleep: syscall_sleep(tf); break;

      case SYS_open: syscall_open(tf); break;
      case SYS_read: syscall_read(tf); break;
      case SYS_write: syscall_write(tf); break;
      case SYS_create: syscall_create(tf); break;
      case SYS_close: syscall_close(tf); break;
      case SYS_delete: syscall_delete(tf); break;
      case SYS_lseek: syscall_lseek(tf); break;
      case SYS_dup: syscall_dup(tf); break;
      case SYS_dup2: syscall_dup2(tf); break;
      case SYS_mkdir: syscall_mkdir(tf); break;
      case SYS_rmdir: syscall_rmdir(tf); break;
      case SYS_lsdir: syscall_lsdir(tf); break;
      case SYS_chdir: syscall_chdir(tf); break;
      //default: panic("Unknown system call type");
   }
}
Esempio n. 6
0
File: shell.c Progetto: Rathcke/uni
int cmd_show(int argc, char** argv) {
  if (argc != 2) {
    printf("Usage: show <file>\n");
    return 1;
  }
  int fd;
  if ((fd=syscall_open(argv[1])) < 0) {
    printf("Could not open %s.  Reason: %d\n", argv[1], fd);
    return 1;
  }

  int rd;
  char buffer[BUFFER_SIZE];
  while ((rd = syscall_read(fd, buffer, BUFFER_SIZE))) {
    int wr=0, thiswr;
    while (wr < rd) {
      if ((thiswr = syscall_write(1, buffer+wr, rd-wr)) <= 0) {
        printf("\nCall to syscall_write() failed.  Reason: %d.\n", wr);
        syscall_close(fd);
        return 1;
      }
      wr += thiswr;
    }
  }
  if (rd < 0) {
    printf("\nCall to syscall_read() failed.  Reason: %d.\n", rd);
    syscall_close(fd);
    return 1;
  } else {
    syscall_close(fd);
    return 0;
  }
}
Esempio n. 7
0
static ssize_t write_plain(struct bus *b, boxed_msg *box) {
    int fd = box->fd;
    uint8_t *msg = box->out_msg;
    size_t msg_size = box->out_msg_size;
    size_t sent_size = box->out_sent_size;
    size_t rem = msg_size - sent_size;
    
    BUS_LOG_SNPRINTF(b, 10, LOG_SENDER, b->udata, 64,
        "write %p to %d, %zd bytes",
        (void*)&msg[sent_size], fd, rem);

    /* Attempt a single write. ('for' is due to continue-based retry.) */
    for (;;) {
        ssize_t wrsz = syscall_write(fd, &msg[sent_size], rem);
        if (wrsz == -1) {
            if (Util_IsResumableIOError(errno)) {
                errno = 0;
                continue;
            } else {
                /* will notify about closed socket upstream */
                BUS_LOG_SNPRINTF(b, 1, LOG_SENDER, b->udata, 64,
                    "write: socket error writing, %s", strerror(errno));
                errno = 0;
                return -1;
            }
        } else if (wrsz > 0) {
            BUS_LOG_SNPRINTF(b, 5, LOG_SENDER, b->udata, 64,
                "sent: %zd", wrsz);
            return wrsz;
        } else {
            return 0;
        }
    }
}
Esempio n. 8
0
int main(int argc, char **argv) {
    if (argc > 1) {
            int i;
            for (i = 1; i < argc; i++) {
                int written = 0;
                int len = strlen(argv[i]);
		if(i > 1)
		{
                    syscall_write(stdout, " " , 1 );
		}
                while (written < len) {
                    written += syscall_write(stdout, (void*)(argv[i] + written), len - written);
                } 
            }
	    syscall_write(stdout, "\n" , 1 );
    }
    return 0;
}
Esempio n. 9
0
/**
 * Handle system calls. Interrupts are enabled when this function is
 * called.
 *
 * @param user_context The userland context (CPU registers as they
 * where when system call instruction was called in userland)
 */
void syscall_handle(context_t *user_context)
{
    /* When a syscall is executed in userland, register a0 contains
     * the number of the syscall. Registers a1, a2 and a3 contain the
     * arguments of the syscall. The userland code expects that after
     * returning from the syscall instruction the return value of the
     * syscall is found in register v0. Before entering this function
     * the userland context has been saved to user_context and after
     * returning from this function the userland context will be
     * restored from user_context.
     */

    int retval;

    switch(user_context->cpu_regs[MIPS_REGISTER_A0]) {
    case SYSCALL_HALT:
        halt_kernel();
        break;
    case SYSCALL_EXEC:
        retval = (int) process_spawn((char*) user_context->cpu_regs[MIPS_REGISTER_A1]);
        user_context->cpu_regs[MIPS_REGISTER_V0] = retval;
        break;
    case SYSCALL_EXIT:
        /* Resources are cleaned up in process_finish(...) */
        process_finish(user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_JOIN:
        retval = process_join(user_context->cpu_regs[MIPS_REGISTER_A1]);
        user_context->cpu_regs[MIPS_REGISTER_V0] = retval;
        break;
    case SYSCALL_READ:
        {
            int fhandle = user_context->cpu_regs[MIPS_REGISTER_A1];
            int buffer = user_context->cpu_regs[MIPS_REGISTER_A2];
            int length = user_context->cpu_regs[MIPS_REGISTER_A3];

            int retval = syscall_read(fhandle, (void *)buffer, length);
            user_context->cpu_regs[MIPS_REGISTER_V0] = retval;
        }
        break;
    case SYSCALL_WRITE:
        {
            int fhandle = user_context->cpu_regs[MIPS_REGISTER_A1];
            int buffer = user_context->cpu_regs[MIPS_REGISTER_A2];
            int length = user_context->cpu_regs[MIPS_REGISTER_A3];

            int retval = syscall_write(fhandle, (void *)buffer, length);
            user_context->cpu_regs[MIPS_REGISTER_V0] = retval;
        }
        break;
    default:
        KERNEL_PANIC("Unhandled system call\n");
    }

    /* Move to next instruction after system call */
    user_context->pc += 4;
}
Esempio n. 10
0
int main(void)
{
    char buffer[64];
    char *ptr = buffer;
    char intro[20] = "Press a button!";
    char *introptr = intro;
    int a = syscall_write(1, introptr, 15);
    int b = syscall_read(0, ptr, 10);
    int c = syscall_write(1, ptr, 10);   
    
    a = a;
    b = b;
    c = c;

    syscall_halt();
    
    return 0;
}
Esempio n. 11
0
int main(void) {

	char file[] = "[arkimedes]hej";
	int handle = syscall_open((char const*) &file);	

	char buffer[128];
	char buffer2[128];

	syscall_read(handle, &buffer, 4);
	syscall_write(handle, &buffer, 4);

	syscall_seek(handle, 0);
	syscall_read(handle, &buffer2, 11);
	syscall_write(FILEHANDLE_STDOUT, &buffer2, 11);

	syscall_close(handle);
	syscall_delete((char const*) &file);

	char file2[] = "[arkimedes]rasputin";
	syscall_create((char const*) &file2, 11);

	char buffer3[] = "\ngorbatjov\n";
	handle = syscall_open((char const*) &file2);	
	
	syscall_write(handle, &buffer3, 11);

	int ret_code = syscall_seek(handle, 12);
	printf("\n%d\n", ret_code);

	syscall_seek(handle, 0);
	syscall_read(handle, &buffer3, 11);
	syscall_write(FILEHANDLE_STDOUT, &buffer3, 11);	

	syscall_close(handle);

	char file3[] = "[arkimedes]putin";
	syscall_create((char const*) &file3, 11);
	handle = syscall_open((char const*) &file3);	

	char buffer4[] = "\ngorbad\n";
	syscall_write(handle, &buffer4, 11);
	
	return 0;
}
Esempio n. 12
0
int main(void)
{
  int i;
  char str[3];

  syscall_write(1, "Hello, I am validprog, I will count to ten!\n",44);
  str[1] = '\n';
  str[2] = '\0';
  
  /* syscall_join(syscall_exec(validprog));*/
  for (i=0; i <= 10; i++)
  {
    str[0] = (char)i+36;
    syscall_write(1,str,2);
  }
  syscall_write(1,"That is it! Goodbye\n",20);
  syscall_exit(4);
  return 0;
}
Esempio n. 13
0
int main(void)
{
  int pipeid;
  char string[4];
  pipeid = syscall_open("[pipe]test");
  syscall_read(pipeid, string, 4);
  syscall_write(1, string, 4);
  printf("\n");
  return 0;
}
Esempio n. 14
0
int main(int argc, char  **argv)
{
	char s[10000];
	int k,sum=0;
	int fd0;
	FILE *fd1;

	initialize();

	if (argc < 3)
	{
		printf("Usage:\n\ncpfile -o fimage-source host-target\ncpfile host-source fimage-target\n");
		exit(0);
	}
	if (strcmp(argv[1], "-o") == 0)
	{
		fd0 = syscall_open(argv[2],O_RDONLY,0);
		fd1 = fopen(argv[3],"wb");

		if (fd0 < 0 || fd1 < 0)
		{
			printf("Error opening input/output files\n");
			exit(0);
		}
		while ((k=syscall_read(fd0, s, 10000))>0)
		{
			fwrite(s,k,1,fd1);
			sum += k;
		}
		syscall_close(fd0);
		fclose(fd1);
	}
	else
	{
		fd0 = syscall_open(argv[2],O_WRONLY,0);
		fd1 = fopen(argv[1],"rb");
		if (fd0 < 0 || fd1 < 0)
		{
			printf("Error opening input/output files\n");
			exit(0);
		}
		
		while ((k=fread(s, 1, 10000, fd1))>0)
		{
			syscall_write(fd0,s,k);
			sum += k;
		}
		syscall_close(fd0);
		fclose(fd1);
	}
	closeall();
	//printf("Image copied\n");
	return 0;
}
Esempio n. 15
0
int main(void) {
    char c;
    
    while(1){
        syscall_read(stdin,&c,1);
        syscall_write(stdout,&c,1);
        if (c == 'q') syscall_halt(); // press 'q' to quit
    }
    
    return 0;
}
Esempio n. 16
0
int main(void) {
    char* str = "balalaikka";
    char* str2 = "ripkukkoparssinen";
    char* ptrs[2];
    ptrs[0] = str;
    ptrs[1] = str2;
    char argc = 2;
    
    syscall_write(stdout, "starting execp test\n", 512);
    int s = syscall_execp("[testi]argprint", argc, (const char**)ptrs);
    return s;
}
Esempio n. 17
0
int printf( char *format, ... ){
	int slen = strlen( format ), i = 0, signed_int;
	unsigned int unsigned_int;
	char buf, *str;
	va_list args;
	va_start( args, format );

	for ( i = 0; i < slen; i++ ){
		if ( format[i] == '%' ){
			switch( format[++i] ){
				case '%':
					buf = '%';
					syscall_write( stdout, &buf, 1 );
					break;
				case 'c':
					buf = va_arg( args, int );
					syscall_write( stdout, &buf, 1 );
					break;
				case 's':
					str = va_arg( args, char * );
					syscall_write( stdout, str, strlen( str ));
					break;
				case 'd':
					signed_int = va_arg( args, int );
					print_num( signed_int );
					break;
				case 'u':
					unsigned_int = va_arg( args, unsigned int );
					print_num( unsigned_int );
					break;
				case 'x':
					unsigned_int = va_arg( args, unsigned int );
					print_hex( unsigned_int );
					break;
			}
		} else {
			syscall_write( stdout, &format[i], 1 );
		}
	}
Esempio n. 18
0
File: shell.c Progetto: Rathcke/uni
int cmd_cp(int argc, char** argv) {
  if (argc != 3 && argc != 4) {
    printf("Usage: cp <from> <to> [size]\n");
    return 1;
  }
  int fd1, fd2;
  int size = argc == 4 ? atoi(argv[3]) : 0;
  if ((fd1=syscall_open(argv[1])) < 0) {
    printf("Could not open %s.  Reason: %d\n", argv[1], fd1);
    return 1;
  }
  if ((fd2=syscall_create(argv[2], size)) < 0) {
    printf("Could not create %s with initial size %d.  Reason: %d\n", argv[2], size, fd2);
    syscall_close(fd1);
    return 1;
  }
  if ((fd2=syscall_open(argv[2])) < 0) {
    printf("Could not open newly created file %s.  Reason: %d\n", argv[2], fd2);
    syscall_close(fd1);
    return 1;
  }
  int ret, i, rd, wr;
  int totalread = 0, totalwritten = 0;
  char buffer[BUFFER_SIZE];
  while ((rd = syscall_read(fd1, buffer, BUFFER_SIZE))) {
    i = 0;
    totalread += rd;
    clearline();
    printf("Read %d bytes, wrote %d bytes.", totalread, totalwritten);
    while (i < rd) {
      if ((wr=syscall_write(fd2, buffer+i, rd-i)) <= 0) {
        printf("\nCall to syscall_write() failed.  Reason: %d.\n", wr);
        if (wr == 0) {
          printf("Did you remember to make the destination file big enough?\n");
        }
        ret=1;
        goto exit;
      }
      totalwritten += wr;
      i += wr;
      clearline();
      printf("Read %d bytes, wrote %d bytes.", totalread, totalwritten);
    }
  }
 exit:
  printf("\n");
  syscall_close(fd1);
  syscall_close(fd2);
  return ret;
}
Esempio n. 19
0
File: lib.c Progetto: Tayacan/OSM
/* Write the string pointed to by s to standard output.  Returns a
   non-negative integer on success. */
int puts(const char* s)
{
  int len = strlen(s);
  int written = 0;
  int ret;

  do {
    ret = syscall_write(stdout, s, len);
    written += ret;
    s += ret;
  } while (written < len && ret > 0);

  return written;
}
Esempio n. 20
0
/*
 * get system call
 */
static void
syscall_handler (struct intr_frame *f)
{
  int *esp = (int *)syscall_user_to_kernel_vaddr(f->esp);
  switch(*esp)
  {
    case SYS_WRITE:
      syscall_write(f);
      break;
    case SYS_EXIT:
      syscall_exit(f);
      break;
    case SYS_HALT:
      syscall_halt(f);
      break;
    case SYS_EXEC:
      syscall_exec(f);
      break;
    case SYS_CREATE:
      syscall_create(f);
      break;
    case SYS_REMOVE:
      syscall_remove(f);
      break;
    case SYS_OPEN:
      syscall_open(f);
      break;
    case SYS_FILESIZE:
      syscall_filesize(f);
      break;
    case SYS_READ:
      syscall_read(f);
      break;
    case SYS_SEEK:
      syscall_seek(f);
      break;
    case SYS_TELL:
      syscall_tell(f);
      break;
    case SYS_CLOSE:
      syscall_close(f);
      break;
    case SYS_WAIT:
      syscall_wait(f);
      break;
  }
}
Esempio n. 21
0
int main(int argc, char **argv) {
    if (argc < 3) {
        prints("Usage: fstest <filename> <n>\n");
        return 1;
    } 

    int blocksize = MAX_BLOCK_SIZE;

    char *filename = argv[1];
    int filesize = atoi(argv[2]);
    if (blocksize > MAX_BLOCK_SIZE) {
        prints("Blocksize must be smaller!\n");
        return 1;
    }

    
    int filehandle = syscall_open(filename);
    if (filehandle < 0) {
        prints("failed to open file!\n");
        return 3;
    }
    
    int written = 0;
    while(written < filesize) {
        int i;
        int write = MIN(filesize - written, blocksize);
        for (i = 0; i < write; i++) {
            buffer[i] = char_for_pos(written + i);
        }
        write = syscall_write(filehandle, (void*)&buffer, write);
        if (write <= 0) {
            prints("failed to write!\n");
            return 3;
        }
        written += write;
    }
    prints("OK, fstest wrote bytes. closing file\n");
    if(syscall_close(filehandle) == -1) {
        prints("OK, fstest file close failed\n");
        return 1;
    }
    
    prints("OK, fstest closed file\n");

    return 0;
}
Esempio n. 22
0
/**
 * Handle system calls. Interrupts are enabled when this function is
 * called.
 *
 * @param user_context The userland context (CPU registers as they
 * where when system call instruction was called in userland)
 */
void syscall_handle(context_t *user_context)
{
    /* When a syscall is executed in userland, register a0 contains
     * the number of the syscall. Registers a1, a2 and a3 contain the
     * arguments of the syscall. The userland code expects that after
     * returning from the syscall instruction the return value of the
     * syscall is found in register v0. Before entering this function
     * the userland context has been saved to user_context and after
     * returning from this function the userland context will be
     * restored from user_context.
     */
    switch(user_context->cpu_regs[MIPS_REGISTER_A0]) {
    case SYSCALL_HALT:
        halt_kernel();
        break;
    case SYSCALL_READ:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_read(user_context->cpu_regs[MIPS_REGISTER_A1],
                         (void *)user_context->cpu_regs[MIPS_REGISTER_A2],
                         user_context->cpu_regs[MIPS_REGISTER_A3]);
        break;
    case SYSCALL_WRITE:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_write(user_context->cpu_regs[MIPS_REGISTER_A1],
                          (const void *)user_context->cpu_regs[MIPS_REGISTER_A2],
                          user_context->cpu_regs[MIPS_REGISTER_A3]);
        break;
    case SYSCALL_EXEC:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_exec((const char *)user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_EXIT:
        syscall_exit(user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_JOIN:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_join(user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    default: 
        KERNEL_PANIC("Unhandled system call\n");
    }

    /* Move to next instruction after system call */
    user_context->pc += 4;
}
Esempio n. 23
0
int main() 
{
  /* setup needed variables */
  int fhin = FILEHANDLE_STDIN;
  char* wbuff = "Oh hello there!! \nwhat is your name?\n";
  char rbuff[64];
  int c;
  
  /* test the calls */
  
  syscall_write(fhin,wbuff,37);
  
  c = syscall_read(fhin,rbuff,63);
  
  wbuff = "Hello";
  syscall_write(fhin,wbuff,5);
  
  syscall_write(fhin,rbuff,c);
  
  wbuff = ", how are you doing today?\n";
  syscall_write(fhin,wbuff,27);
  
  c = syscall_read(fhin,rbuff,63);
  
  wbuff = "Oh you're doing ";
  syscall_write(fhin,wbuff,16);
  
  syscall_write(fhin,rbuff,c);
  
  wbuff = "!!!\n";
  syscall_write(fhin,wbuff, 4);
    
  wbuff = "Go on have a good day now!!";
  syscall_write(fhin,wbuff, 28);
  
  /* ensure proper system shut down */

  syscall_halt();
  
  return 0;
}
Esempio n. 24
0
int main()
{
    char buff[20];
    syscall_delete(file1);
    if (syscall_create(file1, 100) < 0)
        fail("Couldn't create file :(\n");
    int fd = syscall_open(file1);
    if (fd < 0)
        fail("Couldn't open file :(\n");
    printf("Wrote %d bytes\n", syscall_write(fd, "Teststring!\n", 11));

    if (syscall_seek(fd, 0) < 0)
        fail("Couldn't seek :(\n");

    printf("Read %d bytes\n", syscall_read(fd, buff, 20));
    printf(buff);

    syscall_halt();
    return 0;
}
Esempio n. 25
0
uint64_t syscall_exit(int32_t status)
{
    if (curr_task->proc.fstructs[1] && curr_task->proc.pid != -1) {
        syscall_write(1, "\0", 1);
    }
    if (curr_task->proc.pid == 1) {
        if(status == 1){
            update_foreground(&curr_task->proc,&curr_task->proc);
            return 0;
        }
        printf("SBUSH shutting down...\nConsole will be active!\n");
    }
    resume_wait_proc(curr_task->proc.pid);
    add_to_queue(&zqueue, curr_task);
    if (curr_task->proc.fg) {
        update_foreground(curr_task->proc.parent_fg,
                curr_task->proc.parent_fg->parent_fg);
    }
    schedule(SCHED_DELETE, 0);
    return 0;
}
Esempio n. 26
0
/**
 * Handle system calls. Interrupts are enabled when this function is
 * called.
 */
uintptr_t syscall_entry(uintptr_t syscall,
                        uintptr_t arg0, uintptr_t arg1, uintptr_t arg2)
{
  arg0 = arg0;
  arg1 = arg1;
  arg2 = arg2;
  /* When a syscall is executed in userland, register a0 contains
   * the number of the syscall. Registers a1, a2 and a3 contain the
   * arguments of the syscall. The userland code expects that after
   * returning from the syscall instruction the return value of the
   * syscall is found in register v0. Before entering this function
   * the userland context has been saved to user_context and after
   * returning from this function the userland context will be
   * restored from user_context.
   */
  switch(syscall) {
  case SYSCALL_HALT:
    halt_kernel();
    break;
  case SYSCALL_READ:
    return syscall_read((void*)arg1);
    break;
  case SYSCALL_WRITE:
    return syscall_write((const void*)arg1, (int)arg2);
    break;
  case SYSCALL_SPAWN:
    return syscall_spawn((char const*)arg0, (void*) arg1);
    break;
  case SYSCALL_EXIT:
    syscall_exit((int)arg0);
    break;
  case SYSCALL_JOIN:
    return process_join((int)arg0);
    break;
  default:
    KERNEL_PANIC("Unhandled system call\n");
  }

  return 0;
}
Esempio n. 27
0
File: mem0.c Progetto: kazyka/2aar
int main() {
  char* a_string;

  /* Find the current (initial) heap end. */
  a_string = syscall_memlimit(NULL);

  /* Extend the heap, and check that it worked. */
  if (syscall_memlimit(a_string + STRING_LENGTH) == NULL) {
    /* It didn't work, so exit already. */
    return 1;
  }

  /* Copy the source string to the dynamically allocated memory. */
  for (size_t i = 0; i < STRING_LENGTH; i++) {
    a_string[i] = STRING_SOURCE[i];
  }

  /* Write from the dynamically allocated memory. */
  syscall_write(1, a_string, STRING_LENGTH);

  return 0;
}
Esempio n. 28
0
/* ------------------------------------------------------------------------ *
 * Write either to the fd directly or to its queue.                         *
 * ------------------------------------------------------------------------ */
int io_write(int fd, const void *buf, size_t n)
{
  int ret;

  /* Catch invalid arguments */
  if(fd < 0) return -1;
  if(n == 0) return 0;

  /* fd is queued, write to the send queue */
  if(io_list[fd].control.sendq)
  {
    ret = queue_write(&io_list[fd].sendq, buf, n);

    if(io_list[fd].sendq.size)
      io_set_events(fd, IO_WRITE);

    return ret;
  }

  /* Write directly to fd */
  switch(io_list[fd].type)
  {
    case FD_SOCKET:
#ifdef HAVE_SSL
      if(io_list[fd].ssl)
        return ssl_write(fd, buf, n);
      else
#endif
        return syscall_send(fd, buf, n, 0);
    default:
    case FD_FILE:
    case FD_PIPE:
      return syscall_write(fd, buf, n);
  }

  return -1;
}
Esempio n. 29
0
File: lib.c Progetto: Tayacan/OSM
/* Read character from standard input, with echoing.  Returns a
   non-negative integer on success, which can be casted to char. */
int getc(void)
{
  char c = getc_raw();
  syscall_write(stdout, &c, 1); /* Echo back at user. */
  return c;
}
Esempio n. 30
0
File: lib.c Progetto: Tayacan/OSM
/* Write c to standard output.  Returns a positive integer on
   success. */
int putc(char c)
{
  return syscall_write(stdout, &c, 1);
}