Exemplo n.º 1
0
int NXSaveToFile(register NXStream *s, const char *name )
{
    int             fd;
    char           *buf;
    int             len, max, retval;

    _NXVerifyStream(s);
    verify_memory_stream(s);
    fd = open(name, O_WRONLY | O_CREAT, 0666);
    if (fd >= 0) {
	NXGetMemoryBuffer(s, &buf, &len, &max);
	retval = write(fd, buf, len);
	if (retval < 0)
	    return retval;
	retval = ftruncate(fd, len);
	if (retval < 0)
	    return retval;
	retval = fsync(fd);
	if (retval < 0)
	    return retval;
	retval = close(fd);
	if (retval < 0)
	    return retval;
    } else
	return -1;
    return 0;
}
Exemplo n.º 2
0
static void
TransferError(NXStream * s)
{
	char	   *buffer;
	int			len,
				maxlen;

	if (lastError)
		free(lastError);
	NXGetMemoryBuffer(s, &buffer, &len, &maxlen);
	lastError = malloc(len + 1);
	strcpy(lastError, buffer);
}
Exemplo n.º 3
0
static void
TransferError(NXStream * s)
{
	char	   *buffer;
	int			len,
				maxlen;

	if (lastError)
		free(lastError);
	NXGetMemoryBuffer(s, &buffer, &len, &maxlen);
	lastError = malloc(len + 1);
	if(!lastError)
		ereport(ERROR, errcode(ERRCODE_OUT_OF_MEMORY),
			errmsg("Transer error failed: out of memory"));

	strcpy(lastError, buffer);
}
Exemplo n.º 4
0
int
TclpDlopen(
    Tcl_Interp *interp,		/* Used for error reporting. */
    Tcl_Obj *pathPtr,		/* Name of the file containing the desired
				 * code (UTF-8). */
    Tcl_LoadHandle *loadHandle,	/* Filled with token for dynamically loaded
				 * file which will be passed back to
				 * (*unloadProcPtr)() to unload the file. */
    Tcl_FSUnloadFileProc **unloadProcPtr)
				/* Filled with address of Tcl_FSUnloadFileProc
				 * function which should be used for this
				 * file. */
{
    struct mach_header *header;
    char *fileName;
    char *files[2];
    CONST char *native;
    int result = 1;

    NXStream *errorStream = NXOpenMemory(0,0,NX_READWRITE);

    fileName = Tcl_GetString(pathPtr);

    /*
     * First try the full path the user gave us. This is particularly
     * important if the cwd is inside a vfs, and we are trying to load using a
     * relative path.
     */

    native = Tcl_FSGetNativePath(pathPtr);
    files = {native,NULL};

    result = rld_load(errorStream, &header, files, NULL);

    if (!result) {
	/*
	 * Let the OS loader examine the binary search path for whatever
	 * string the user gave us which hopefully refers to a file on the
	 * binary path
	 */

	Tcl_DString ds;

	native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds);
	files = {native,NULL};
	result = rld_load(errorStream, &header, files, NULL);
	Tcl_DStringFree(&ds);
    }

    if (!result) {
	char *data;
	int len, maxlen;

	NXGetMemoryBuffer(errorStream,&data,&len,&maxlen);
	Tcl_AppendResult(interp, "couldn't load file \"", fileName, "\": ",
		data, NULL);
	NXCloseMemory(errorStream, NX_FREEBUFFER);
	return TCL_ERROR;
    }
    NXCloseMemory(errorStream, NX_FREEBUFFER);

    *loadHandle = (Tcl_LoadHandle)1; /* A dummy non-NULL value */
    *unloadProcPtr = &TclpUnloadFile;

    return TCL_OK;
}