Example #1
0
int open (const char *file)
{
  struct file *f = filesys_open (file);
  if (!f) {
    return -1;
  }

  return process_add_file(f);
}
Example #2
0
/* Open file */
int 
open(const char* file)
{
	int fd;
	struct file* f = filesys_open(file);
	if( f == NULL )
		return (int)-1;
	fd = process_add_file(f);
	return (int)fd;
}
Example #3
0
File: io.c Project: mrb852/osm-exam
openfile_t io_open(const char* pathname)
{
  openfile_t file = vfs_open(pathname);
  if (file < 0) {
    return file;
  }
  else {
    process_add_file(file);
    /* Don't return a value that can be mistaken for stdin, stdout, or
       stderr. */
    return file + 3;
  }
}
Example #4
0
/* open file and return fd */
int
open(const char *file)
{
	int fd;
	struct file *new_file;
	new_file=filesys_open(file);

	if(new_file != NULL)
	{
		fd = process_add_file(new_file);
		return fd;
	}
	else
	{
		return -1;
	}
}
Example #5
0
/************************************************************************************************************
 * Function name : get_next_assignment                                                                      *
 *   													    *
 *     INPUT  :	char *filename										    *
 *		unsigned int *exponent									    *
 *		int *bit_min										    *
 *		int *bit_max										    *
 *		char *assignment_key[100];
 *     OUTPUT :                                        							    *
 *                                                                                                          *
 *     0 - OK												    *
 *     1 - get_next_assignment : cannot open file							    *
 *     2 - get_next_assignment : no valid assignment found						    *
 ************************************************************************************************************/
enum ASSIGNMENT_ERRORS get_next_assignment(char *filename, unsigned int *exponent, unsigned int *bit_min, unsigned int *bit_max, LINE_BUFFER *key, int verbosity)
{
  FILE *f_in;
  
  enum PARSE_WARNINGS value;
  struct ASSIGNMENT assignment;
  char *tail;
  LINE_BUFFER line;
  unsigned int linecount=0;

  // first, make sure we have an up-to-date worktodo file
  process_add_file(filename);
  f_in = fopen_and_lock(filename, "r");
  if(f_in == NULL)
  {
    printf("Can't open workfile %s\n", filename);
    return CANT_OPEN_FILE;	// nothing to open...
  }
  for(;;)
  {
    linecount++;
    value = parse_worktodo_line(f_in,&assignment,&line,&tail);
    if ((BLANK_LINE == value) || (NONBLANK_LINE == value))
      continue;
    if (NO_WARNING == value)
    {
      if (valid_assignment(assignment.exponent,assignment.bit_min, assignment.bit_max, verbosity))
        break;
      value = INVALID_DATA;
    }

    if (END_OF_FILE == value)
      break;
    if(verbosity >= 1)
    {
      printf("WARNING: ignoring line %u in \"%s\"! Reason: ", linecount, filename);
      switch(value)
      {
        case LONG_LINE:           printf("line is too long\n"); break;
        case NO_FACTOR_EQUAL:     printf("doesn't begin with Factor=\n");break;
        case INVALID_FORMAT:      printf("invalid format\n");break;
        case INVALID_DATA:        printf("invalid data\n");break;
        default:                  printf("unknown error on >%s<",line); break;
      }
    }
  }

  unlock_and_fclose(f_in);

  if (NO_WARNING == value)
  {
    *exponent = assignment.exponent;
    *bit_min = assignment.bit_min;
    *bit_max = assignment.bit_max;

    if (key!=NULL)strcpy(*key,assignment.assignment_key);

    return OK;
  }
  else
    return VALID_ASSIGNMENT_NOT_FOUND;
}