void FileAccess::store_byte(Uint8 p_dest) {
	ERR_FAIL_COND(!f);

	ERR_FAIL_COND( !(current_mode&WRITE ) );
	
	if ( fwrite(&p_dest,1,1,f)==0 ) check_for_errors();
}
void FileAccess::get_byte_array(Uint8 *p_dest,int p_elements) {
	ERR_FAIL_COND(!f);
	
	ERR_FAIL_COND( !(current_mode&READ ) );
	
	if ( fread(p_dest,p_elements,1,f)==0 ) check_for_errors();
}
Uint32 FileAccess::get_pos() {
	ERR_FAIL_COND_V(!f,0);

	Uint32 aux_position;
	if ( !(aux_position = ftell(f)) ) {
		check_for_errors();
	};
	return aux_position;
};
Uint8 FileAccess::get_byte() {

	ERR_FAIL_COND_V(!f,0);
	ERR_FAIL_COND_V( !(current_mode&READ ) , 0 );
	
	Uint8 byte;
	if ( fread(&byte,1,1,f)==0 ) 
		check_for_errors();
	
	return byte;
}
Example #5
0
/*-------------------------------------------------------------------------
 * Function:    run_flush_verification_process
 *
 * Purpose:     This function is used to communicate with the test script
 *              in order to spawn off a process to verify that a flush
 *              of an individual object was successful. 
 * 
 * Return:      0 on Success, 1 on Failure
 *
 * Programmer:  Mike McGreevy
 *              July 16, 2010
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t run_flush_verification_process(const char * obj_pathname, const char * expected) 
{
    /* Send Signal to SCRIPT indicating that it should kick off a verification process. */
    send_signal(SIGNAL_TO_SCRIPT, obj_pathname, expected);

    /* Wait for Signal from SCRIPT indicating that verification process has completed. */
    if (wait_for_signal(SIGNAL_FROM_SCRIPT) < 0) TEST_ERROR;

    /* Check to see if any errors occurred */
    if (check_for_errors() < 0) TEST_ERROR;

    /* Return */
    return SUCCEED;

error:
    return FAIL;

} /* run_flush_verification_process */
Example #6
0
/*-------------------------------------------------------------------------
 * Function:    start_refresh_verification_process
 *
 * Purpose:     This function is used to communicate with the test script
 *              in order to spawn off a process which will test the
 *              H5*refresh routine.
 * 
 * Return:      0 on Success, 1 on Failure
 *
 * Programmer:  Mike McGreevy
 *              July 16, 2010
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t start_refresh_verification_process(const char * obj_pathname) 
{
    /* Send Signal to SCRIPT indicating that it should kick off a refresh 
       verification process */
    send_signal(SIGNAL_TO_SCRIPT, obj_pathname, NULL);
    
    /* Wait for Signal from VERIFICATION PROCESS indicating that it's opened the
       target object and ready for MAIN PROCESS to modify it */
    if (wait_for_signal(SIGNAL_BETWEEN_PROCESSES_1) < 0) TEST_ERROR;

    /* Check to see if any errors occurred */
    if (check_for_errors() < 0) TEST_ERROR;

    /* Return */
    return SUCCEED;

error:
    return FAIL;

} /* start_refresh_verification_process */
Example #7
0
/*-------------------------------------------------------------------------
 * Function:    end_refresh_verification_process
 *
 * Purpose:     This function is used to communicate with the verification
 *              process spawned by the start_refresh_verification_process 
 *              function. It gives it the go-ahead to call H5*refresh
 *              on an object and conlcude the refresh verification.
 * 
 * Return:      0 on Success, 1 on Failure
 *
 * Programmer:  Mike McGreevy
 *              July 16, 2010
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t end_refresh_verification_process(void) 
{
    /* Send Signal to REFRESH VERIFICATION PROCESS indicating that the object
        has been modified and it should now attempt to refresh its metadata,
        and verify the results. */
    send_signal(SIGNAL_BETWEEN_PROCESSES_2, NULL, NULL);

    /* Wait for Signal from SCRIPT indicating that the refresh verification
        process has completed. */
    if (wait_for_signal(SIGNAL_FROM_SCRIPT) < 0) TEST_ERROR;

    /* Check to see if any errors occurred */
    if (check_for_errors() < 0) TEST_ERROR;

    /* Return */

    return SUCCEED;

error:
    return FAIL;

} /* end_refresh_verification_process */
static GtkTextBuffer *
read_boot_log (const char  *file, 
               int         *seen_errors, 
               GError     **error)
{
  char *content;
  char *content_utf8;
  gsize length;
  char *p, *q;
  GtkTextBuffer *buffer;
  GtkTextIter iter;
  GString *partial;

  if (!g_file_get_contents (file, &content, &length, error))
    return NULL;

  content_utf8 = g_locale_to_utf8 (content, length, NULL, NULL, NULL);
  if (content_utf8)
    {
      g_free (content);
      content = content_utf8;   
    }
  
  if (check_for_errors (file))
    *seen_errors = 2;
  else
    *seen_errors = 0;

  buffer = gtk_text_buffer_new (NULL);
  gtk_text_buffer_create_tag (buffer, "blue", "foreground", "blue", NULL);
  gtk_text_buffer_create_tag (buffer, "green", "foreground", "green", NULL);
  gtk_text_buffer_create_tag (buffer, "red", "foreground", "red", NULL);
  gtk_text_buffer_create_tag (buffer, "yellow", "foreground", "yellow", NULL);

  partial = g_string_new ("");

  p = content;
  while (*p) 
    {
      switch (*p) 
        {
          case '\r': 
            /* keep isolated \r */
            if (p[1] != '\r' && p[-1] != '\r' &&
                p[1] != '\n' && p[-1] != '\n')
              {
                gtk_text_buffer_get_end_iter (buffer, &iter);
                gtk_text_buffer_insert (buffer, &iter, p, 1);
              }
            p++;
            break;
          case '\t':
            gtk_text_buffer_get_end_iter (buffer, &iter);
            gtk_text_buffer_insert (buffer, &iter, "        ", 8); 
            p++;
            break;
          case '\033':
            if (strncmp (p, "\033[0;34m", 7) == 0 && (q = strstr (p, "\033[0;39m")))
              {
                p += 7;
                gtk_text_buffer_get_end_iter (buffer, &iter);
                gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, p, q - p, "blue", NULL); 
                p = q + 7; 
              }
            else if (strncmp (p, "\033[60G", 5) == 0) 
              {
                gtk_text_buffer_get_end_iter (buffer, &iter);
                gtk_text_buffer_insert (buffer, &iter, "\t", 1);
                p += 5;
              }
            else if (strncmp (p, "\033[0;31m", 7) == 0 && (q = strstr (p, "\033[0;39m")))
              {
                p += 7;
                gtk_text_buffer_get_end_iter (buffer, &iter);
                gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, p, q - p, "red", NULL); 
                p = q + 7; 
              }
            else if (strncmp (p, "\033[0;32m", 7) == 0 && (q = strstr (p, "\033[0;39m")))
              {
                p += 7;
                gtk_text_buffer_get_end_iter (buffer, &iter);
                gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, p, q - p, "green", NULL); 
                p = q + 7; 
              }
            else if (strncmp (p, "\033[0;33m", 7) == 0 && (q = strstr (p, "\033[0;39m")))
              {
                p += 7;
                gtk_text_buffer_get_end_iter (buffer, &iter);
                gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, p, q - p, "yellow", NULL); 
                p = q + 7; 
              }
            else if (strncmp (p, "\033%G", 3) == 0) 
              p += 3;
            else
              p++;
            break;
          default:
            /* GtkTextBuffer doesn't let us insert partial utf-8 characters */
            g_string_append_c (partial, *p);
            if (g_utf8_get_char_validated (partial->str, partial->len) != (gunichar)-2)
              {
                gtk_text_buffer_get_end_iter (buffer, &iter);
                gtk_text_buffer_insert (buffer, &iter, partial->str, partial->len);
                g_string_truncate (partial, 0);
              }
            p++;
            break;
        }
    }

  g_string_free (partial, TRUE);
  g_free (content);

  return buffer;
}
void FileAccess::store_byte_array(const Uint8 *p_dest,int p_elements) {

	ERR_FAIL_COND(!f);
	ERR_FAIL_COND( !(current_mode&WRITE ) );
	if ( fwrite(p_dest,p_elements,1,f)==0 ) check_for_errors();
}
Example #10
0
void FileAccess::seek_end() {
	ERR_FAIL_COND(!f);

	if ( fseek(f,0,SEEK_END) ) check_for_errors();
}
Example #11
0
void FileAccess::seek(Uint32 p_position) {

	ERR_FAIL_COND(!f);
	if ( fseek(f,p_position,SEEK_SET) ) check_for_errors();
}
Example #12
0
/**

  This is the main function from the HTTP 
  server. Every new connection from a client
  is handled here. Here the request from the
  client is handled.
  */
void HTTPServer( GN::ClientList&, GN::CSocket & s )
{
	try
	{
		// buffer pentru cererea HTTP
		char buffer[ MAX_REQUEST_RECEIVE_BUFFER+2 ];

		HttpRequest	req;		// Clasa pentru procesare cerere HTTP
		HttpUrl url;			// Clasa pentru procesare URL
		HttpResponse r;			// Clasa pentru raspunsul HTTP
		
		// receptioneaza cerere
		int ret = s.receive( buffer, MAX_REQUEST_RECEIVE_BUFFER );
		buffer[ret]=0;

		// proceseaza cererea primita
		req.parse( buffer, ret );
		check_for_errors( s, req );

		// parse url
		url.parse( req.url(), WWW_FOLDER );
				
		// Verifica daca exista fisierul
		FILE * file = fopen( url.file(), "r");
		if( !file  )
		{
			r.redirect( STD_404_PAGE );
			r.send(s);

			GSTD::CError error( 0, "File not found");
			throw error;
		}
		fclose(file);
		
		// Trimite raspunsul ok - fisierul exista si continutul va fi trimis
		r.set_status( HTTP_OK );
		
		r.set("Server", "GCWS 1.0");
		r.set("Connection","close");
	
		// incarca DLL
		
		// seteaza tipul continutului
		get_content_type( url.ext(), buffer );
		r.set("Content-type", buffer );
		
		// trimite raspunsul cu toate campurile setate corespunzator
		r.send(s);

		// send file - one buffer at time
		file = fopen( url.file(), "rb" );
		int nb;
		do
		{
			nb = fread( buffer, 1, MAX_REQUEST_RECEIVE_BUFFER, file );
			if( nb ) s.send( buffer, nb );
		}while( nb );
		fclose( file );

		// if( url.is_set("debug") ) dump_request( req, url, s );

	}
	catch( GSTD::CError error )
	{
		throw error;
	}
}
Example #13
0
/*
 * md back-end code for menu-driven BSD disklabel editor.
 */
int
md_make_bsd_partitions(void)
{
	FILE *f;
	int i, j, pl;
	EBZB *bzb;

	/*
	 * Scan for any problems and report them before continuing.
	 *  The user can abort installation and we'll take them back
	 *  to the main menu; continue ignoring the warnings, or
	 *  ask to reedit the Disk Partition Map.
	 */
	while (1) {
	    if (check_for_errors()) {
	        process_menu (MENU_sanity, NULL);
	        if (yesno < 0)
		    return 0;
	        else if (yesno)
		    break;
	        edit_diskmap();
	    } else
		break;
	}

	/* Build standard partitions */
	memset(&bsdlabel, 0, sizeof bsdlabel);

	/*
	 * The mac68k port has a predefined partition for "c" which
	 *  is the size of the disk, everything else is unused.
	 */
	bsdlabel[RAW_PART].pi_size = dlsize;
	/*
	 * Now, scan through the Disk Partition Map and transfer the
	 *  information into the incore disklabel.
	 */
	for (i=0;i<map.usable_cnt;i++) {
	    j = map.mblk[i];
	    bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
	    if (bzb->flags.part) {
		pl = bzb->flags.part - 'a';
		switch (whichType(&map.blk[j])) {
		    case HFS_PART:
			bsdlabel[pl].pi_fstype = FS_HFS;
			strcpy (bsdlabel[pl].pi_mount, (char *)bzb->mount_point);
			break;
		    case ROOT_PART:
		    case UFS_PART:
			bsdlabel[pl].pi_fstype = FS_BSDFFS;
			strcpy (bsdlabel[pl].pi_mount, (char *)bzb->mount_point);
			bsdlabel[pl].pi_flags |= PIF_NEWFS | PIF_MOUNT;
			break;
		    case SWAP_PART:
			bsdlabel[pl].pi_fstype = FS_SWAP;
			break;
		    case SCRATCH_PART:
			bsdlabel[pl].pi_fstype = FS_OTHER;
			strcpy (bsdlabel[pl].pi_mount, (char *)bzb->mount_point);
		    default:
			break;
		}
	        if (bsdlabel[pl].pi_fstype != FS_UNUSED) {
		    bsdlabel[pl].pi_size = map.blk[j].pmPartBlkCnt;
		    bsdlabel[pl].pi_offset = map.blk[j].pmPyPartStart;
		    if (bsdlabel[pl].pi_fstype != FS_SWAP) {
		        bsdlabel[pl].pi_frag = 8;
		        bsdlabel[pl].pi_fsize = 1024;
		    }
		}
	    }
	}

	/* Disk name  - don't bother asking, just use the physical name*/
	strcpy (bsddiskname, diskdev);

#ifdef DEBUG
	f = fopen ("/tmp/disktab", "w");
#else
	f = fopen ("/etc/disktab", "w");
#endif
	if (f == NULL) {
		endwin();
		(void) fprintf (stderr, "Could not open /etc/disktab");
		exit (1);
	}
	(void)fprintf (f, "%s|NetBSD installation generated:\\\n", bsddiskname);
	(void)fprintf (f, "\t:dt=%s:ty=winchester:\\\n", disktype);
	(void)fprintf (f, "\t:nc#%d:nt#%d:ns#%d:\\\n", dlcyl, dlhead, dlsec);
	(void)fprintf (f, "\t:sc#%d:su#%" PRIu32 ":\\\n", dlhead*dlsec, (uint32_t)dlsize);
	(void)fprintf (f, "\t:se#%d:%s\\\n", blk_size, doessf);
	for (i=0; i<8; i++) {
		if (bsdlabel[i].pi_fstype == FS_HFS)
		    (void)fprintf (f, "\t:p%c#%d:o%c#%d:t%c=macos:",
			       'a'+i, bsdlabel[i].pi_size,
			       'a'+i, bsdlabel[i].pi_offset,
			       'a'+i);
		else
		    (void)fprintf (f, "\t:p%c#%d:o%c#%d:t%c=%s:",
			       'a'+i, bsdlabel[i].pi_size,
			       'a'+i, bsdlabel[i].pi_offset,
			       'a'+i, getfslabelname(bsdlabel[i].pi_fstype));
		if (bsdlabel[i].pi_fstype == FS_BSDFFS)
			(void)fprintf (f, "b%c#%d:f%c#%d",
			   'a'+i, bsdlabel[i].pi_fsize * bsdlabel[i].pi_frag,
			   'a'+i, bsdlabel[i].pi_fsize);
		if (i < 7)
			(void)fprintf (f, "\\\n");
		else
			(void)fprintf (f, "\n");
	}
	fclose (f);

	/* Everything looks OK. */
	return 1;
}