예제 #1
0
파일: teehistorian.cpp 프로젝트: Laxa/ddnet
	void ExpectFull(const unsigned char *pOutput, int OutputSize)
	{
		const ::testing::TestInfo *pTestInfo =
			::testing::UnitTest::GetInstance()->current_test_info();
		const char *pTestName = pTestInfo->name();

		if(m_Buffer.Error()
			|| m_Buffer.Size() != OutputSize
			|| mem_comp(m_Buffer.Data(), pOutput, OutputSize) != 0)
		{
			char aFilename[64];
			IOHANDLE File;

			str_format(aFilename, sizeof(aFilename), "%sGot.teehistorian", pTestName);
			File = io_open(aFilename, IOFLAG_WRITE);
			ASSERT_TRUE(File);
			io_write(File, m_Buffer.Data(), m_Buffer.Size());
			io_close(File);

			str_format(aFilename, sizeof(aFilename), "%sExpected.teehistorian", pTestName);
			File = io_open(aFilename, IOFLAG_WRITE);
			ASSERT_TRUE(File);
			io_write(File, pOutput, OutputSize);
			io_close(File);
		}

		ASSERT_FALSE(m_Buffer.Error());
		ASSERT_EQ(m_Buffer.Size(), OutputSize);
		ASSERT_TRUE(mem_comp(m_Buffer.Data(), pOutput, OutputSize) == 0);
	}
예제 #2
0
IOHANDLE engine_openfile(const char *filename, int flags)
{
	char buffer[1024];
	
	if(flags&IOFLAG_WRITE)
	{
		engine_savepath(filename, buffer, sizeof(buffer));
		return io_open(buffer, flags);
	}
	else
	{
		IOHANDLE handle = 0;
		
		/* check current directory */
		handle = io_open(filename, flags);
		if(handle)
			return handle;
			
		/* check user directory */
		engine_savepath(filename, buffer, sizeof(buffer));
		handle = io_open(buffer, flags);
		if(handle)
			return handle;
			
		/* check normal data directory */
		str_format(buffer, sizeof(buffer), "%s/%s", datadir, filename);
		handle = io_open(buffer, flags);
		if(handle)
			return handle;
	}
	return 0;		
}
예제 #3
0
	// Open a file. This checks that the path appears to be a subdirectory
	// of one of the storage paths.
	virtual IOHANDLE OpenFile(const char *pFilename, int Flags, int Type, char *pBuffer = 0, int BufferSize = 0)
	{
		char aBuffer[MAX_PATH_LENGTH];
		if(!pBuffer)
		{
			pBuffer = aBuffer;
			BufferSize = sizeof(aBuffer);
		}

		// Check whether the path contains '..' (parent directory) paths. We'd
		// normally still have to check whether it is an absolute path
		// (starts with a path separator (or a drive name on windows)),
		// but since we concatenate this path with another path later
		// on, this can't become absolute.
		//
		// E. g. "/etc/passwd" => "/path/to/storage//etc/passwd", which
		// is safe.
		if(str_check_pathname(pFilename) != 0)
		{
			pBuffer[0] = 0;
			dbg_msg("Storage", "OpenFile: check failed with %s", pFilename);
			return 0;
		}

		// open file
		if(Flags&IOFLAG_WRITE)
		{
			dbg_msg("Storage", "OpenFile: io_open with %s", GetPath(TYPE_SAVE, pFilename, pBuffer, BufferSize));
			return io_open(GetPath(TYPE_SAVE, pFilename, pBuffer, BufferSize), Flags);
		}
		else
		{
			IOHANDLE Handle = 0;

			if(Type == TYPE_ALL)
			{
				// check all available directories
				for(int i = 0; i < m_NumPaths; ++i)
				{
					Handle = io_open(GetPath(i, pFilename, pBuffer, BufferSize), Flags);
					if(Handle)
						return Handle;
				}
			}
			else if(Type >= 0 && Type < m_NumPaths)
			{
				// check wanted directory
				Handle = io_open(GetPath(Type, pFilename, pBuffer, BufferSize), Flags);
				if(Handle)
					return Handle;
			}
		}

		pBuffer[0] = 0;
		return 0;
	}
예제 #4
0
파일: storage.cpp 프로젝트: BannZay/ddnet
	virtual IOHANDLE OpenFile(const char *pFilename, int Flags, int Type, char *pBuffer = 0, int BufferSize = 0)
	{
		char aBuffer[MAX_PATH_LENGTH];
		if(!pBuffer)
		{
			pBuffer = aBuffer;
			BufferSize = sizeof(aBuffer);
		}

		if(Type == TYPE_ABSOLUTE)
		{
			return io_open(pFilename, Flags);
		}
		if(str_startswith(pFilename, "mapres/../skins/"))
		{
			pFilename = pFilename + 10; // just start from skins/
		}
		if(pFilename[0] == '/' || pFilename[0] == '\\' || str_find(pFilename, "../") != NULL || str_find(pFilename, "..\\") != NULL
		#ifdef CONF_FAMILY_WINDOWS
			|| (pFilename[0] && pFilename[1] == ':')
		#endif
		)
		{
			// don't escape base directory
		}
		else if(Flags&IOFLAG_WRITE)
		{
			return io_open(GetPath(TYPE_SAVE, pFilename, pBuffer, BufferSize), Flags);
		}
		else
		{
			IOHANDLE Handle = 0;

			if(Type <= TYPE_ALL)
			{
				// check all available directories
				for(int i = 0; i < m_NumPaths; ++i)
				{
					Handle = io_open(GetPath(i, pFilename, pBuffer, BufferSize), Flags);
					if(Handle)
						return Handle;
				}
			}
			else if(Type >= 0 && Type < m_NumPaths)
			{
				// check wanted directory
				Handle = io_open(GetPath(Type, pFilename, pBuffer, BufferSize), Flags);
				if(Handle)
					return Handle;
			}
		}

		pBuffer[0] = 0;
		return 0;
	}
예제 #5
0
파일: options.c 프로젝트: jlsandell/tig
static enum status_code
load_option_file(const char *path)
{
	struct config_state config = { path, 0, FALSE };
	struct io io;
	char buf[SIZEOF_STR];

	/* Do not read configuration from stdin if set to "" */
	if (!path || !strlen(path))
		return SUCCESS;

	if (!prefixcmp(path, "~/")) {
		const char *home = getenv("HOME");

		if (!home || !string_format(buf, "%s/%s", home, path + 2))
			return ERROR_HOME_UNRESOLVABLE;
		path = buf;
	}

	/* It's OK that the file doesn't exist. */
	if (!io_open(&io, "%s", path))
		return ERROR_FILE_DOES_NOT_EXIST;

	if (io_load(&io, " \t", read_option, &config) == ERR ||
	    config.errors == TRUE)
		warn("Errors while loading %s.", path);
	return SUCCESS;
}
예제 #6
0
FILE *io_fopen (const char *path, const char *mode, int u) {
  /* first set the current umask */
  if (mode[0] == 'w') {
    int fd;
    int flags = O_CREAT | O_EXCL;

#ifdef O_NOFOLLOW
    flags |= O_NOFOLLOW;
#endif

    if (mode[1] == '+')
      flags |= O_RDWR;
    else
      flags |= O_WRONLY;

    if ((fd = io_open (path, flags, u)) < 0)
      return (NULL);

    return (fdopen (fd, mode));
  }
  else {
    if (u > 0)
      umask (u);
    return (fopen (path, mode));
  }
}
예제 #7
0
파일: options.c 프로젝트: MarkTseng/tig
static enum status_code
load_option_file(const char *path)
{
	struct config_state config = { path, 0, FALSE };
	struct io io;
	char buf[SIZEOF_STR];

	/* Do not read configuration from stdin if set to "" */
	if (!path || !strlen(path))
		return SUCCESS;

	if (!prefixcmp(path, "~/")) {
		const char *home = getenv("HOME");

		if (!home || !string_format(buf, "%s/%s", home, path + 2))
			return error("Failed to expand ~ to user home directory");
		path = buf;
	}

	/* It's OK that the file doesn't exist. */
	if (!io_open(&io, "%s", path)) {
		/* XXX: Must return ERROR_FILE_DOES_NOT_EXIST so missing
		 * system tigrc is detected properly. */
		if (io_error(&io) == ENOENT)
			return ERROR_FILE_DOES_NOT_EXIST;
		return error("Error loading file %s: %s", path, strerror(io_error(&io)));
	}

	if (io_load_span(&io, " \t", &config.lineno, read_option, &config) == ERR ||
	    config.errors == TRUE)
		warn("Errors while loading %s.", path);
	return SUCCESS;
}
예제 #8
0
파일: stdio.c 프로젝트: fywtat/curie
struct io *io_open_stderr ()
{
    struct io *out = io_open (2);

    out->type = iot_write;

    return out;
}
예제 #9
0
파일: stdio.c 프로젝트: fywtat/curie
struct io *io_open_stdout ()
{
    struct io *out = io_open (1);

    out->type = iot_write;

    return out;
}
예제 #10
0
파일: stdio.c 프로젝트: fywtat/curie
struct io *io_open_stdin ()
{
    struct io *in = io_open (0);

    in->type = iot_read;

    return in;
}
예제 #11
0
파일: pashas.c 프로젝트: sabrown256/pactnew
void PA_file_mon(char *edname, char *ppname, char *gfname)
   {int64_t curpos;
    
/* check on the edit file */
    if (PA_gs.edit_file != NULL)
       {if (_PA.edstr == 0L)
           _PA.edstr = io_tell(PA_gs.edit_file);
        curpos = io_tell(PA_gs.edit_file);

        if (curpos+_PA.edstr >= MAXSIZE)
           {io_close(PA_gs.edit_file);
            PA_advance_name(edname);
            PA_gs.edit_file = io_open(edname, "w");
            PA_ERR((PA_gs.edit_file == NULL),
                   "CAN'T OPEN FILE %s - PA_FILE_MON", edname);
            PRINT(stdout, "Edit file %s opened\n", edname);
            _PA.edstr = 0L;};};

/* check on the post processor */
    if (PA_gs.pp_file != NULL)
       {FILE *str;

	str = PA_gs.pp_file->stream;

        if (_PA.ppstr == 0L)
           _PA.ppstr = lio_tell(str);
        curpos = lio_tell(str);

        if (curpos+_PA.ppstr >= MAXSIZE)
           {PA_close_pp();
            PA_advance_name(ppname);
            PA_gs.pp_file = PA_open(ppname, "w", FALSE);
            PRINT(stdout, "Post processor file %s opened\n", ppname);
            _PA.ppstr = 0L;};};

/* check on the PVA file */
    if (PA_gs.pva_file != NULL)
       {FILE *str;

	str = PA_gs.pva_file->stream;

        if (_PA.ppstr == 0L)
           _PA.ppstr = lio_tell(str);
        curpos = lio_tell(str);

        if (curpos+_PA.ppstr >= MAXSIZE)
           {PD_close(PA_gs.pva_file);
            PA_advance_name(gfname);

            PA_gs.pva_file = PA_open(gfname, "w", FALSE);
            PA_ERR(((PA_gs.pva_file == NULL) ||
		    (PD_def_mapping(PA_gs.pva_file) == 0)),

                   "CAN`T DEFINE MAPPINGS - PA_FILE_MON");
            PRINT(stdout, "PVA file %s opened\n", gfname);
            _PA.ppstr = 0L;};};

    return;}
예제 #12
0
파일: mp3.c 프로젝트: ecthiender/mocp-git
static struct mp3_data *mp3_open_internal (const char *file,
		const int buffered)
{
	struct mp3_data *data;

	data = (struct mp3_data *)xmalloc (sizeof(struct mp3_data));
	data->ok = 0;
	decoder_error_init (&data->error);

	/* Reset information about the file */
	data->freq = 0;
	data->channels = 0;
	data->skip_frames = 0;
	data->bitrate = -1;
	data->avg_bitrate = -1;

	/* Open the file */
	data->io_stream = io_open (file, buffered);
	if (io_ok(data->io_stream)) {
		data->ok = 1;
		
		data->size = io_file_size (data->io_stream);

		mad_stream_init (&data->stream);
		mad_frame_init (&data->frame);
		mad_synth_init (&data->synth);

		if (options_get_int("Mp3IgnoreCRCErrors"))
				mad_stream_options (&data->stream,
					MAD_OPTION_IGNORECRC);
		
		data->duration = count_time_internal (data);
		mad_frame_mute (&data->frame);
		data->stream.next_frame = NULL;
		data->stream.sync = 0;
		data->stream.error = MAD_ERROR_NONE;

		if (io_seek(data->io_stream, SEEK_SET, 0) == (off_t)-1) {
			decoder_error (&data->error, ERROR_FATAL, 0,
						"seek failed");
			io_close (data->io_stream);
			mad_stream_finish (&data->stream);
			mad_frame_finish (&data->frame);
			mad_synth_finish (&data->synth);
			data->ok = 0;
		}

		data->stream.error = MAD_ERROR_BUFLEN;
	}
	else {
		decoder_error (&data->error, ERROR_FATAL, 0, "Can't open: %s",
				io_strerror(data->io_stream));
		io_close (data->io_stream);
	}

	return data;
}
예제 #13
0
파일: display.c 프로젝트: noscripter/tig
enum status_code
open_script(const char *path)
{
	if (is_script_executing())
		return error("Scripts cannot be run from scripts");

	return io_open(&script_io, "%s", path)
		? SUCCESS : error("Failed to open %s", path);
}
예제 #14
0
int test_10(char *base, char *tgt, int n)
   {int err;
    char datfile[MAXLINE], fname[MAXLINE];
    PDBfile *strm;
    FILE *fp;

/* target the file as asked */
    test_target(tgt, base, 100+n, fname, datfile, MAXLINE);

    fp = io_open(fname, "w");

    prep_test_10_data();

    if (read_only == FALSE)

/* create the named file */
       {strm = PD_create(datfile);
	if (strm == NULL)
	   error(1, fp, "Test couldn't create file %s\r\n", datfile);
	PRINT(fp, "File %s created\n", datfile);

/* write the test data */
	write_test_10_data(strm);

/* close the file */
	if (PD_close(strm) == FALSE)
	   error(1, fp, "Test couldn't close file %s\r\n", datfile);
	PRINT(fp, "File %s closed\n", datfile);};

/* reopen the file */
    strm = PD_open(datfile, "r");
    if (strm == NULL)
       error(1, fp, "Test couldn't open file %s\r\n", datfile);
    PRINT(fp, "File %s opened\n", datfile);

/* dump the symbol table */
    dump_test_symbol_table(fp, strm->symtab, 1);

/* read the data from the file */
    read_test_10_data(strm);

/* compare the original data with that read in */
    err = compare_test_10_data(strm, fp);

/* close the file */
    if (PD_close(strm) == FALSE)
       error(1, fp, "Test couldn't close file %s\r\n", datfile);
    PRINT(fp, "File %s closed\n", datfile);

/* print it out to STDOUT */
    print_test_10_data(fp);

    io_close(fp);
    if (err)
       REMOVE(fname);

    return(err);}
예제 #15
0
파일: storage.cpp 프로젝트: BannZay/ddnet
	void LoadPaths(const char *pArgv0)
	{
		// check current directory
		IOHANDLE File = io_open("storage.cfg", IOFLAG_READ);
		if(!File)
		{
			// check usable path in argv[0]
			unsigned int Pos = ~0U;
			for(unsigned i = 0; pArgv0[i]; i++)
				if(pArgv0[i] == '/' || pArgv0[i] == '\\')
					Pos = i;
			if(Pos < MAX_PATH_LENGTH)
			{
				char aBuffer[MAX_PATH_LENGTH];
				str_copy(aBuffer, pArgv0, Pos+1);
				str_append(aBuffer, "/storage.cfg", sizeof(aBuffer));
				File = io_open(aBuffer, IOFLAG_READ);
			}

			if(Pos >= MAX_PATH_LENGTH || !File)
			{
				dbg_msg("storage", "couldn't open storage.cfg");
				return;
			}
		}

		char *pLine;
		CLineReader LineReader;
		LineReader.Init(File);

		while((pLine = LineReader.Get()))
		{
			const char *pLineWithoutPrefix = str_startswith(pLine, "add_path ");
			if(pLineWithoutPrefix)
			{
				AddPath(pLineWithoutPrefix);
			}
		}

		io_close(File);

		if(!m_NumPaths)
			dbg_msg("storage", "no paths found in storage.cfg");
	}
예제 #16
0
파일: bme_gfx.c 프로젝트: neuromancer/BOFH
int gfx_loadsprites(int num, char *name)
{
    int handle, size, c;
    int datastart;

    if (!gfx_spriteheaders)
    {
        gfx_setmaxspritefiles(DEFAULT_MAX_SPRFILES);
    }

    bme_error = BME_OPEN_ERROR;
    if (num >= gfx_maxspritefiles) return BME_ERROR;

    gfx_freesprites(num);

    handle = io_open(name);
    if (handle == -1) return BME_ERROR;

    size = io_lseek(handle, 0, SEEK_END);
    io_lseek(handle, 0, SEEK_SET);

    gfx_spriteamount[num] = io_readle32(handle);

    gfx_spriteheaders[num] = malloc(gfx_spriteamount[num] * sizeof(SPRITEHEADER));

    if (!gfx_spriteheaders[num])
    {
        bme_error = BME_OUT_OF_MEMORY;    
        io_close(handle);
        return BME_ERROR;
    }

    for (c = 0; c < gfx_spriteamount[num]; c++)
    {
        SPRITEHEADER *hptr = gfx_spriteheaders[num] + c;

        hptr->xsize = io_readle16(handle);
        hptr->ysize = io_readle16(handle);
        hptr->xhot = io_readle16(handle);
        hptr->yhot = io_readle16(handle);
        hptr->offset = io_readle32(handle);
    }

    datastart = io_lseek(handle, 0, SEEK_CUR);
    gfx_spritedata[num] = malloc(size - datastart);
    if (!gfx_spritedata[num])
    {
        bme_error = BME_OUT_OF_MEMORY;    
        io_close(handle);
        return BME_ERROR;
    }
    io_read(handle, gfx_spritedata[num], size - datastart);
    io_close(handle);
    bme_error = BME_OK;
    return BME_OK;
}
예제 #17
0
파일: io.c 프로젝트: lubing521/HDSegmenter
int main(int argc, char **argv)
{
    int fd = io_open("abc");
    uint8_t buffer[1024];
    int c = io_read(fd, buffer, 1024);
  // printf("%s \n", buffer);
    printf("%d\n", c);
    io_close(fd);
    
}
예제 #18
0
void ReadNews()
{
	IOHANDLE newsFile = io_open("news", IOFLAG_READ);
	if (!newsFile)
		return;

	io_read(newsFile, m_aNews, NEWS_SIZE);

	io_close(newsFile);
}
예제 #19
0
/* Read data from a file in package */
static int fip_file_read(io_entity_t *entity, uintptr_t buffer, size_t length,
			  size_t *length_read)
{
	int result;
	file_state_t *fp;
	size_t file_offset;
	size_t bytes_read;
	uintptr_t backend_handle;

	assert(entity != NULL);
	assert(buffer != (uintptr_t)NULL);
	assert(length_read != NULL);
	assert(entity->info != (uintptr_t)NULL);

	/* Open the backend, attempt to access the blob image */
	result = io_open(backend_dev_handle, backend_image_spec,
			 &backend_handle);
	if (result != 0) {
		WARN("Failed to open FIP (%i)\n", result);
		result = -ENOENT;
		goto fip_file_read_exit;
	}

	fp = (file_state_t *)entity->info;

	/* Seek to the position in the FIP where the payload lives */
	file_offset = fp->entry.offset_address + fp->file_pos;
	result = io_seek(backend_handle, IO_SEEK_SET, file_offset);
	if (result != 0) {
		WARN("fip_file_read: failed to seek\n");
		result = -ENOENT;
		goto fip_file_read_close;
	}

	result = io_read(backend_handle, buffer, length, &bytes_read);
	if (result != 0) {
		/* We cannot read our data. Fail. */
		WARN("Failed to read payload (%i)\n", result);
		result = -ENOENT;
		goto fip_file_read_close;
	} else {
		/* Set caller length and new file position. */
		*length_read = bytes_read;
		fp->file_pos += bytes_read;
	}

/* Close the backend. */
 fip_file_read_close:
	io_close(backend_handle);

 fip_file_read_exit:
	return result;
}
예제 #20
0
	virtual IOHANDLE OpenFile(const char *pFilename, int Flags, char *pBuffer = 0, int BufferSize = 0)
	{
		char aBuffer[1024];
		if(!pBuffer)
		{
			pBuffer = aBuffer;
			BufferSize = sizeof(aBuffer);
		}
		
		if(Flags&IOFLAG_WRITE)
		{
			str_format(pBuffer, BufferSize, "%s/%s", m_aApplicationSavePath, pFilename);
			return io_open(pBuffer, Flags);
		}
		else
		{
			IOHANDLE Handle = 0;
			
			// check current directory
			Handle = io_open(pFilename, Flags);
			if(Handle)
				return Handle;
				
			// check user directory
			str_format(pBuffer, BufferSize, "%s/%s", m_aApplicationSavePath, pFilename);
			Handle = io_open(pBuffer, Flags);
			if(Handle)
				return Handle;
				
			// check normal data directory
			str_format(pBuffer, BufferSize, "%s/%s", m_aDatadir, pFilename);
			Handle = io_open(pBuffer, Flags);
			if(Handle)
				return Handle;
		}
		
		pBuffer[0] = 0;
		return 0;		
	}
예제 #21
0
	virtual IOHANDLE OpenFile(const char *pFilename, int Flags, int Type, char *pBuffer = 0, int BufferSize = 0)
	{
		char aBuffer[MAX_PATH_LENGTH];
		if(!pBuffer)
		{
			pBuffer = aBuffer;
			BufferSize = sizeof(aBuffer);
		}

		if(Flags&IOFLAG_WRITE)
		{
			return io_open(GetPath(TYPE_SAVE, pFilename, pBuffer, BufferSize), Flags);
		}
		else
		{
			IOHANDLE Handle = 0;

			if(Type == TYPE_ALL)
			{
				// check all available directories
				for(int i = 0; i < m_NumPaths; ++i)
				{
					Handle = io_open(GetPath(i, pFilename, pBuffer, BufferSize), Flags);
					if(Handle)
						return Handle;
				}
			}
			else if(Type >= 0 && Type < m_NumPaths)
			{
				// check wanted directory
				Handle = io_open(GetPath(Type, pFilename, pBuffer, BufferSize), Flags);
				if(Handle)
					return Handle;
			}
		}

		pBuffer[0] = 0;
		return 0;
	}
예제 #22
0
void engine_getpath(char *buffer, int buffer_size, const char *filename, int flags)
{
	if(flags&IOFLAG_WRITE)
		engine_savepath(filename, buffer, buffer_size);
	else
	{
		IOHANDLE handle = 0;
		
		/* check current directory */
		handle = io_open(filename, flags);
		if(handle)
		{
			str_copy(buffer, filename, buffer_size);
			io_close(handle);
			return;
		}
			
		/* check user directory */
		engine_savepath(filename, buffer, buffer_size);
		handle = io_open(buffer, flags);
		if(handle)
		{
			io_close(handle);
			return;
		}
			
		/* check normal data directory */
		str_format(buffer, buffer_size, "%s/%s", datadir, filename);
		handle = io_open(buffer, flags);
		if(handle)
		{
			io_close(handle);
			return;
		}
	}
	
	buffer[0] = 0;
}
예제 #23
0
파일: dev9.c 프로젝트: kyuba/dev9
static void connect_to_netlink(struct dfs *fs)
{
    struct sockaddr_nl nls = { 0, 0, 0, 0 };
    int fd;
    struct io *io;
    int newlength = NETLINK_BUFFER;
    struct exec_context *context;

    nls.nl_family = AF_NETLINK;
    nls.nl_pid = sys_getpid();
    nls.nl_groups = -1;

    fd = sys_socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);

    if (fd < 0) { cexit (17); }

    if (sys_bind(fd, (void *)&nls, sizeof(struct sockaddr_nl)) < 0) {
        cexit (18);
    }

    if (sys_setsockopt (fd, SOL_SOCKET, SO_RCVBUF, (char *)&newlength,
                        sizeof (int)) < 0) {
        cexit(19);
    }

    if (sys_fcntl (fd, F_SETFD, FD_CLOEXEC) < 0) {
        cexit(20);
    }

    if (sys_fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
        cexit(21);
    }

    io = io_open (fd);
    io->type = iot_read;

    multiplex_add_io (io, on_netlink_read, on_netlink_close, (void *)fs);

    context = execute(EXEC_CALL_NO_IO, (char **)0, (char **)0);
    switch (context->pid)
    {
        case -1:
            cexit (25);
        case 0:
            ping_for_uevents ("/sys/(bus|class|block)/.+/.+/uevent");
            cexit (0);
        default:
            multiplex_add_process(context, mx_on_subprocess_death, (void *)0);
    }
}
예제 #24
0
파일: display.c 프로젝트: phschoen/tig
enum status_code
open_script(const char *path)
{
	if (is_script_executing())
		return error("Scripts cannot be run from scripts");

	char buf[SIZEOF_STR];

	if (!expand_path(buf, sizeof(buf), path))
		return error("Failed to expand path: %s", path);

	return io_open(&script_io, "%s", buf)
		? SUCCESS : error("Failed to open %s", buf);
}
예제 #25
0
bool CNetServer::Open(NETADDR BindAddr, CNetBan *pNetBan, int MaxClients, int MaxClientsPerIP, int Flags)
{
	// zero out the whole structure
	mem_zero(this, sizeof(*this));

	// open socket
	m_Socket = net_udp_create(BindAddr);
	if(!m_Socket.type)
		return false;

	m_pNetBan = pNetBan;

	// clamp clients
	m_MaxClients = MaxClients;
	if(m_MaxClients > NET_MAX_CLIENTS)
		m_MaxClients = NET_MAX_CLIENTS;
	if(m_MaxClients < 1)
		m_MaxClients = 1;

	m_MaxClientsPerIP = MaxClientsPerIP;

	IOHANDLE urandom = io_open("/dev/urandom", IOFLAG_READ);
	if (urandom) {
		io_read(urandom, m_SecurityTokenSeed, sizeof(m_SecurityTokenSeed));
		io_close(urandom);
	}
	else
	{
		dbg_msg("security", "/dev/urandom is not available. using sv_rcon_password for security token seed, make sure you have a long password!");
		str_copy(m_SecurityTokenSeed, g_Config.m_SvRconPassword, sizeof(m_SecurityTokenSeed));
		long timestamp = time_get();
		md5_state_t md5;
		md5_byte_t digest[16];
		// do over 9000 rounds of md5 on the rcon password, to make it harder to recover the password from the token values
		for (int i = 0; i < 1000000; i++)
		{
			md5_init(&md5);
			md5_append(&md5, (unsigned char*)m_SecurityTokenSeed, sizeof(m_SecurityTokenSeed));
			md5_append(&md5, (unsigned char*)&timestamp, sizeof(timestamp));
			md5_finish(&md5, digest);
			mem_copy(m_SecurityTokenSeed, digest, sizeof(m_SecurityTokenSeed) < sizeof(digest) ? sizeof(m_SecurityTokenSeed) : sizeof(digest));
		}
	}

	for(int i = 0; i < NET_MAX_CLIENTS; i++)
		m_aSlots[i].m_Connection.Init(m_Socket, true);

	return true;
}
예제 #26
0
static int open_memmap(const uintptr_t spec)
{
    int result = IO_FAIL;
    uintptr_t local_image_handle;

    result = io_dev_init(memmap_dev_handle, memmap_init_params);
    if (result == IO_SUCCESS) {
        result = io_open(memmap_dev_handle, spec, &local_image_handle);
        if (result == IO_SUCCESS) {
            /* INFO("Using Memmap IO\n"); */
            io_close(local_image_handle);
        }
    }
    return result;
}
예제 #27
0
void _PA_init_files(const char *edname, const char *ppname,
		    const char *gfname)
   {

/* make the name of the first edit file */
    if (edname != NULL)
       {PA_gs.edit_file = io_open(edname, "w");
	PA_ERR((PA_gs.edit_file == NULL),
	       "CAN'T OPEN FILE %s - _PA_INIT_FILES", edname);
	PRINT(stdout, "Edit file %s opened\n", edname);};

/* initialize the post processor file */
    _PA_init_pp(ppname, gfname);

    return;}
예제 #28
0
파일: edb.c 프로젝트: Knio/everdb-native
int
edb_open(edb **const dbp, const char *const fname, int readonly, int overwrite) {
  /*
  open everdb database file `fname`

  bool readonly   open db as read-only; all write ops will fail
                  db file must exist

  bool overwrite  create a new, empty database, even if fname already exists
                  existing db will be destroyed
                  readonly must be false
  */

  int err = 0;
  LOG_DEBUG("edb_open: %p from:%s readonly:%d overwrite:%d\n",
      dbp, fname, readonly, overwrite);

  edb *db = calloc(1, sizeof(edb));
  *dbp = db;

  CHECK(io_open(db, fname, readonly, overwrite));

  int is_new = 0;
  if (overwrite || (readonly = 0 && db->nblocks == 1)) {
    is_new = 1;
  }

  db->readonly = readonly;
  db->freelist = EDB_FREELIST_PRIMARY;
  db->objlist = EDB_OBJLIST;

  if (is_new) {
    CHECK(edb_init(db));
  }

  else {
    CHECK(edb_check(db));
  }

  return err;

  err:
  io_close(db);
  free(db);
  *dbp = NULL;

  return err;
}
예제 #29
0
static int open_semihosting(const uintptr_t spec)
{
	int result;
	uintptr_t local_image_handle;

	/* See if the file exists on semi-hosting.*/
	result = io_dev_init(sh_dev_handle, (uintptr_t)NULL);
	if (result == 0) {
		result = io_open(sh_dev_handle, spec, &local_image_handle);
		if (result == 0) {
			VERBOSE("Using Semi-hosting IO\n");
			io_close(local_image_handle);
		}
	}
	return result;
}
예제 #30
0
파일: updater.cpp 프로젝트: nheir/HClient
bool CUpdater::SelfDelete()
{
	#ifdef CONF_FAMILY_WINDOWS
        IOHANDLE bhFile = io_open("du.bat", IOFLAG_WRITE);
        if (!bhFile)
            return false;

        const char *fileCode = ":_R\r\ndel \"teeworlds.exe\"\r\nif exist \"teeworlds.exe\" goto _R\r\nrename \"tw_tmp.exe\" \"teeworlds.exe\"\r\n:_T\r\nif not exist \"teeworlds.exe\" goto _T\r\nstart teeworlds.exe\r\ndel \"du.bat\"\r\n\0";
        io_write(bhFile, fileCode, str_length(fileCode));
        io_close(bhFile);
	#else
		fs_remove("teeworlds");
	#endif

	return true;
}