Пример #1
0
rt_private void parsing_compiler_write(size_t size)
{
	RT_GET_CONTEXT
	char* cmps_out_ptr = cmps_general_buffer;
	lzo_uint cmps_out_size = (lzo_uint) cmp_buffer_size;
	int signed_cmps_out_size;
	int number_written;

	REQUIRE("cmp_buffer_size not too big", cmp_buffer_size <= 0x7FFFFFFF);
	REQUIRE("size not too big", size <= 0x7FFFFFFF);
	
	lzo1x_1_compress (
					(unsigned char *) general_buffer,		/* Current buffer location */
					(lzo_uint) size,	/* Current buffer size */
					(unsigned char *) cmps_out_ptr,		/* Output buffer for compressed data */
					&cmps_out_size,		/* Size of output buffer and then size of compressed data */
					wrkmem);			/* Memory allocator */

	signed_cmps_out_size = (int) cmps_out_size;

		/* Write size of compressed data */
	if (write (file_descriptor, (char *) &signed_cmps_out_size, sizeof(int)) <= 0)
		eraise ("Unable to write compressed data size", EN_IO);

		/* Write compressed data */
	while (signed_cmps_out_size > 0) {
		number_written = write (file_descriptor, cmps_out_ptr, signed_cmps_out_size);
		if (number_written <= 0)
			eio();
		signed_cmps_out_size -= number_written;
		cmps_out_ptr += number_written;
	}
}
Пример #2
0
rt_private int run_idr_read (IDR *bu)
{
	RT_GET_CONTEXT
	register char * ptr = bu->i_buf;
	int32 read_size;
	long amount_left;
	register int part_read;
	register int total_read = 0;

	if ((char_read_func ((char *)(&read_size), sizeof (int32))) < sizeof (int32))
		eise_io("Independent retrieve: unable to read buffer size.");

	read_size = ntohl (read_size);
#ifdef DEBUG
	if (read_size > idrs_size (bu))
		print_err_msg(stderr, "Too large %d info for %d buffer\n", read_size, idrs_size (bu));
#endif

	amount_left = read_size;
	while (total_read < read_size) {
		if ((part_read = char_read_func (ptr, amount_left)) <= 0) {
				/* If we read 0 bytes, it means that we reached the end of file,
				 * so we are missing something, instead of going further we stop */
			eio();
		}
		total_read += part_read;
		ptr += part_read;
		amount_left -= part_read;
		}
	return total_read;
}
Пример #3
0
rt_public long store_append(EIF_INTEGER f_desc, char *object, fnptr mid, fnptr nid, EIF_REFERENCE s)
{
	/* Append `object' in file `f', and applies routine `mid'
	 * on server `s'. Return position in the file where the object is
	 * stored. */

	/* Initialization */
	server = s;

	if ((file_position = lseek ((int) f_desc, 0, SEEK_END)) == -1)
		eraise ("Unable to seek on internal data files", EN_SYS);

		/* Initialize store context used to store objects for appending. */
	rt_setup_store (&parsing_context, BASIC_STORE);

	parsing_store_append(&parsing_context, object, mid, nid);

		/* Write `parsing_buffer' onto `f_desc'. If we cannot write `parsing_position' bytes
		 * we have a failure. */
	if (write (f_desc, parsing_buffer, parsing_position) != parsing_position) {
		eio();
	}

	parsing_position = 0;

	return file_position;
}
Пример #4
0
rt_private size_t parsing_retrieve_read_with_compression (void)
{
	RT_GET_CONTEXT
	void* dcmps_in_ptr = (char *)0;
	void* dcmps_out_ptr = (char *)0;
	lzo_uint dcmps_in_size = 0;
	lzo_uint dcmps_out_size = (lzo_uint) cmp_buffer_size;
	char* ptr = (char *)0;
	int read_size = 0;
	int part_read = 0;
	int l_bytes_read;

	REQUIRE("cmp_buffer_size not too big", cmp_buffer_size <= 0xFFFFFFFF);

	ptr = cmps_general_buffer;
	l_bytes_read = char_read_func ((char *) &read_size, sizeof(int));
	if ((l_bytes_read < 0) || ((size_t) l_bytes_read < sizeof(int))) {
	  eio();
	}

	dcmps_in_size = read_size;

	while (read_size > 0) {
		part_read = char_read_func (ptr, read_size);
		if (part_read <= 0)
				/* If we read 0 bytes, it means that we reached the end of file,
				 * so we are missing something, instead of going further we stop */
			eio();
		read_size -= part_read;
		ptr += part_read;
	}
	
	dcmps_in_ptr = cmps_general_buffer;
	dcmps_out_ptr = general_buffer;
	
	lzo1x_decompress (dcmps_in_ptr, dcmps_in_size,
					dcmps_out_ptr, &dcmps_out_size, NULL);

	CHECK("dcmps_out_size_positive", dcmps_out_size > 0);
	return dcmps_out_size;
}
Пример #5
0
EIF_INTEGER c_select_poll(EIF_INTEGER fd)
	/*x Get read status for socket fd */
{
	fd_set fdmask;
	struct timeval timeout;

	timeout.tv_sec = (unsigned long) 0;
	timeout.tv_usec = (long) 0;

	FD_ZERO(&fdmask);
	FD_SET(fd, &fdmask);

	if (select(fd + 1, &fdmask, (fd_set *) 0, (fd_set *) 0, &timeout) < 0)
		eio();
	return (FD_ISSET(fd, &fdmask));
}
Пример #6
0
void write_sqconfig(const char *dir, const char *configfile, const char *val)
{
	char *p=malloc(strlen(dir) + strlen(configfile) + 2);

	struct maildir_tmpcreate_info createInfo;
	FILE *fp;

	if (!p)	enomem();

	strcat(strcat(strcpy(p, dir), "/"), configfile);
	if (!val)
	{
		unlink(p);
		free(p);
		return;
	}

	maildir_tmpcreate_init(&createInfo);

	createInfo.maildir=dir;
	createInfo.uniq="config";
	createInfo.doordie=1;

	fp=maildir_tmpcreate_fp(&createInfo);

	if (!fp)
		enomem();


	free(createInfo.newname);
	createInfo.newname=p;

	fprintf(fp, "%s\n", val);
	fflush(fp);
	if (ferror(fp))	eio("Error after write:",p);
	fclose(fp);

	/* Note - umask should already turn off the 077 bits, but
	** just in case someone screwed up previously, I'll fix it
	** myself */

	chmod(createInfo.tmpname, 0600);
	rename(createInfo.tmpname, createInfo.newname);
	maildir_tmpcreate_free(&createInfo);
}
Пример #7
0
EIF_INTEGER c_check_exception_with_timeout(EIF_INTEGER fd, 
									       EIF_INTEGER timeout)
	/*x Get exception status for socket fd within `timeout' seconds */
{
	fd_set fdmask;
	struct timeval tmout;
	int res;

	tmout.tv_sec = (unsigned long) timeout;
	tmout.tv_usec = (long) 0;

	FD_ZERO(&fdmask);
	FD_SET(fd, &fdmask);

	res = select(fd + 1, (fd_set *) 0, (fd_set *) 0, &fdmask, &tmout);

	if (res < 0)
		eio();
	return (FD_ISSET(fd, &fdmask));
}
Пример #8
0
void host_address_from_name (EIF_POINTER addr, EIF_POINTER name)
	/*x 32-bits netid/hostid set in addr from hostname name */
{
	struct hostent *hp;
#ifdef VXWORKS
	int h_errno = 0;
#endif

	EIF_NET_INITIALIZE;

#ifdef VXWORKS
	hp = NULL;
#else
	hp = gethostbyname((char *) name);
#endif

	if (hp == (struct hostent *) 0) {
#ifdef EIF_WINDOWS
		eif_net_check(EIFNET_ERROR_HAPPENED);
#else
			/* On Unix, `gethostbyname' does not set errno, but h_errno. This is why
			 * we cannot use `eif_net_check'. */
		errno = h_errno;
		if (h_errno == HOST_NOT_FOUND) {
			eraise ("The specified host is unknown.", EN_ISE_IO);
		} else if (h_errno == NO_ADDRESS || h_errno == NO_DATA) {
			eraise ("The requested name is valid but does not have an IP address.", EN_ISE_IO);
		} else if (h_errno == NO_RECOVERY) {
			eraise ("A non-recoverable name server error occurred.", EN_ISE_IO);
		} else if (h_errno == TRY_AGAIN) {
			eraise ("A temporary error occurred on an authoritative name server. Try again later.", EN_ISE_IO);
		} else {
			eio();
		}
#endif
	}

	((struct in_addr *) addr)->s_addr = ((struct in_addr *) (hp->h_addr))->s_addr;
}
Пример #9
0
rt_private void run_idr_write (IDR *bu)
{
	RT_GET_CONTEXT
	register char * ptr = idrs_buf (bu);
	int32 host_send, send_size = (int32) (bu->i_ptr - ptr);
	register int number_writen;

#ifdef DEBUG
	if (send_size == 0)
		print_err_msg(stderr, "send size equal zero");
#endif

	host_send = htonl (send_size - sizeof(int32));
	memcpy (ptr, &host_send, sizeof(int32));

	while (send_size > 0) {
		if ((number_writen = char_write_func (ptr, (int) send_size)) <= 0)
			eio();
		send_size -= number_writen;
		ptr += number_writen;
		}
}
Пример #10
0
/* read = 1, check the socket to be ready for reading */ 
int net_socket_ready (int read)
{
	GTCX
	struct timeval tm;
	fd_set fdset;
	int num_active;

	/* Maximum time we should wait for the socket to be ready */
	tm.tv_sec = 60;
	tm.tv_usec = 0;

	
	/* If the select call is interrupted (GET_SOCKET_ERROR =
           EINTR), we have to do the select again */
	for (;;)
	{
		FD_ZERO (&fdset);
		FD_SET (socket_fides, &fdset);

		if (read) {
			/* Wait until the socket is ready for reading*/
			num_active = select (socket_fides + 1, &fdset, NULL, NULL,
					     &tm);
		} else {
				/* Wait until the socket is ready for writing*/
			num_active = select (socket_fides + 1, NULL, &fdset, NULL,
					     &tm);
		}
		
		if (num_active != SOCKET_ERROR) {
			break;
		} else if (GET_SOCKET_ERROR != EINTR)  {
			eio();
		}
	} 

	return (FD_ISSET (socket_fides, &fdset));
}
Пример #11
0
EIF_INTEGER c_select_poll_with_timeout(EIF_INTEGER fd, 
		                               EIF_BOOLEAN read_mode,
									   EIF_INTEGER timeout)
	/*x Get read/write status for socket fd within `timeout' seconds */
{
	fd_set fdmask;
	struct timeval tmout;
	int res;

	tmout.tv_sec = (unsigned long) timeout;
	tmout.tv_usec = (long) 0;

	FD_ZERO(&fdmask);
	FD_SET(fd, &fdmask);

	if (read_mode)
		res = select(fd + 1, &fdmask, (fd_set *) 0, (fd_set *) 0, &tmout);
	else
		res = select(fd + 1, (fd_set *) 0, &fdmask, (fd_set *) 0, &tmout);

	if (res < 0)
		eio();
	return (FD_ISSET(fd, &fdmask));
}
Пример #12
0
rt_public void eif_show_console(void)
	/* Create a new DOS console if needed (i.e. in case of a Windows application. */
{
	if (!eif_console_allocated) {
		HANDLE eif_conin, eif_conout, eif_conerr;
		CONSOLE_SCREEN_BUFFER_INFO csbi;
		BOOL bLaunched;
		int hCrt;
		STARTUPINFO l_info;
#ifndef EIF_BORLAND
		FILE *hf;
#endif
		RT_GET_CONTEXT

			/* Find out if the calling process has initialized the HANDLEs. */
		memset(&l_info, 0, sizeof(STARTUPINFO));
		GetStartupInfo(&l_info);
		if ((l_info.dwFlags & STARTF_USESTDHANDLES) != STARTF_USESTDHANDLES) {
			AllocConsole();
		}

			/* Get all default standard handles */
		eif_conin = GetStdHandle (STD_INPUT_HANDLE);
		eif_conout = GetStdHandle (STD_OUTPUT_HANDLE);
		eif_conerr = GetStdHandle (STD_ERROR_HANDLE);

			/* Check if handles are available, allocate console if not */
			/* Raise an I/O exception if we cannot get a valid handle */
		if ((eif_conin == 0) || (eif_conin == INVALID_HANDLE_VALUE)) {
			AllocConsole ();
			eif_conin = GetStdHandle (STD_INPUT_HANDLE);
		}
		if (eif_conin == INVALID_HANDLE_VALUE) {
			eio ();
		}
		if ((eif_conout == 0) || (eif_conout == INVALID_HANDLE_VALUE)){
			AllocConsole ();
			eif_conout = GetStdHandle (STD_OUTPUT_HANDLE);
		}
		if (eif_conout == INVALID_HANDLE_VALUE) {
			eio ();
		}
		if ((eif_conerr == 0) || (eif_conerr == INVALID_HANDLE_VALUE)) {
			AllocConsole ();
			eif_conerr = GetStdHandle (STD_ERROR_HANDLE);
		}
		if (eif_conerr == INVALID_HANDLE_VALUE) {
			eio ();
		}

			/* If console was manually created, we are most likely in
			 * a Windows application that tries to output something.
			 * Therefore we need to correctly associated all standard
			 * handles `stdin', `stdout' and `stderr' to the new
			 * created console.
			 * Code was adapted from http://codeguru.earthweb.com/console/Console.html
			 * But also checkout Microsoft support web site:
			 * 	http://support.microsoft.com/default.aspx?scid=kb;EN-US;q105305
			 * 
			 * Note: For Borland, the above trick does not work, one has to
			 *  duplicate the handle, unfortunately the solution does not work
			 *  with Microsoft which explains the ifdef statement.
			 */
		EIF_CONSOLE_LOCK;
		if (!eif_console_allocated) {
			if (_get_osfhandle (_fileno (stdout)) != (intptr_t) eif_conout) {
				hCrt = _open_osfhandle ((intptr_t) eif_conout, _O_TEXT);
#ifdef EIF_BORLAND
				dup2 (hCrt, _fileno(stdout));
#else
				hf = _fdopen (hCrt, "w");
				*stdout = *hf;
#endif
			  	setvbuf(stdout, NULL, _IONBF, 0);
			}

			if (_get_osfhandle (_fileno (stderr)) != (intptr_t) eif_conerr) {
				hCrt = _open_osfhandle ((intptr_t) eif_conerr, _O_TEXT);
#ifdef EIF_BORLAND
				dup2 (hCrt, _fileno(stderr));
#else
				hf = _fdopen (hCrt, "w");
				*stderr = *hf;
#endif
			  	setvbuf(stderr, NULL, _IONBF, 0);
			}

			if (_get_osfhandle (_fileno (stdin)) != (intptr_t) eif_conin) {
				hCrt = _open_osfhandle ((intptr_t) eif_conin, _O_TEXT | _O_RDONLY);
#ifdef EIF_BORLAND
				dup2 (hCrt, _fileno(stdin));
#else
				hf = _fdopen (hCrt, "r");
				*stdin = *hf;
#endif
			}

				/* We are computing the cursor position to figure out, if the application
				* has been launched from a DOS console or from the Windows Shell
				*/
			GetConsoleScreenBufferInfo(eif_conout, &csbi);
			bLaunched = ((csbi.dwCursorPosition.X == 0) && (csbi.dwCursorPosition.Y == 0));
			if ((csbi.dwSize.X <= 0) || (csbi.dwSize.Y <= 0))
				bLaunched = FALSE;

			if (bLaunched == TRUE)
				eif_register_cleanup (eif_console_cleanup);

			eif_console_allocated = TRUE;
		}
		EIF_CONSOLE_UNLOCK;
	}
}
Пример #13
0
void eif_link_driver (EIF_OBJECT c_code_dir, EIF_OBJECT system_name, EIF_OBJECT prelink_command_name, EIF_OBJECT driver_name)
{
#if defined EIF_WINDOWS || defined EIF_OS2
	char *source_exe, *target_exe;
	FILE *fi, *fo;
	char buffer[4096];
	size_t amount;

		/* Link */
	amount = strlen (eif_access(driver_name));
	source_exe = (char *) malloc(amount + 1);
	if (source_exe == (char *)0)
		enomem();
	strncpy (source_exe, eif_access (driver_name), amount);
	source_exe [amount] = '\0';
	fi = fopen (source_exe, "rb");
	target_exe = malloc (strlen (eif_access (system_name)) + strlen (eif_access (c_code_dir)) + 6);
	sprintf (target_exe, "%s\\%s.exe", eif_access (c_code_dir), eif_access (system_name));
	fo = fopen (target_exe, "wb");

	amount = 4096;
	while (amount == 4096) {
		amount = fread (buffer, sizeof(char), amount, fi);
		if (amount != fwrite (buffer, sizeof(char), amount, fo))
			eio();
	}

	fclose (fi);
	fclose (fo);
	free (source_exe);
	free (target_exe);

#elif defined EIF_VMS
	char *cmd; size_t cmd_len; 
	const char *c_code_dir_cstr  = eif_access (c_code_dir);
	const char *system_name_cstr = eif_access (system_name);
	const char *prelink_cmd_cstr = eif_access (prelink_command_name);	    /* what is this for? */
	const char *driver_name_cstr = eif_access (driver_name);
	char driver_name_vms[PATH_MAX +1], c_code_dir_vms[PATH_MAX +1];
	int res;

	/* translate driver name and c code directory to VMS filespec syntax */
	eifrt_vms_filespec (driver_name_cstr, driver_name_vms);
	eifrt_vms_filespec (c_code_dir_cstr,  c_code_dir_vms);

	/* allocate buffer for command, add 10 bytes of overhead for COPY command verb, spaces, and terminator */
	cmd_len = strlen(driver_name_vms) + strlen(c_code_dir_vms) + strlen(system_name_cstr) + 10;
	cmd = malloc (cmd_len);
	if (cmd == NULL) {
	    enomem();
	} else {
		sprintf (cmd, "COPY %s %s%s", driver_name_vms, c_code_dir_vms, system_name_cstr);
		assert (strlen(cmd) < cmd_len);
		printf ("$ %s\n",cmd);
		res = eif_system (cmd);
		free (cmd);
	}

#else
	char *cmd;

	cmd = malloc(20 + strlen(eif_access(c_code_dir)) + strlen(eif_access(system_name)) +
					strlen(eif_access(prelink_command_name)) + strlen(eif_access(driver_name)));
	if (cmd == (char *)0) {
		enomem();
	} else {
		sprintf(cmd, "\"%s\" \"%s\" \"%s/%s\"", eif_access(prelink_command_name),
			 eif_access(driver_name), eif_access(c_code_dir),
			 eif_access(system_name));

		(void) eif_system(cmd);
		free(cmd);
	}
#endif
}