Example #1
0
File: pls.c Project: IAPark/vlc
/*****************************************************************************
 * Import_PLS: main import function
 *****************************************************************************/
int Import_PLS( vlc_object_t *p_this )
{
    stream_t *p_demux = (stream_t *)p_this;
    const uint8_t *p_peek;

    CHECK_FILE(p_demux);

    if( vlc_stream_Peek( p_demux->p_source , &p_peek, 10 ) < 10 ) {
        msg_Dbg( p_demux, "not enough data" );
        return VLC_EGENERIC;
    }

    if( strncasecmp( (const char *)p_peek, "[playlist]", 10 )
     && strncasecmp( (const char *)p_peek, "[Reference]", 10 )
     && !stream_HasExtension( p_demux, ".pls" ) )
        return VLC_EGENERIC;

    msg_Dbg( p_demux, "found valid PLS playlist file");
    p_demux->pf_readdir = ReadDir;
    p_demux->pf_control = access_vaDirectoryControlHelper;

    return VLC_SUCCESS;
}
Example #2
0
File: ram.c Project: MarkYuan/vlc
/**
 * Import_RAM: main import function
 * @param p_this: this demux object
 * @return VLC_SUCCESS if everything is okay
 */
int Import_RAM( vlc_object_t *p_this )
{
    demux_t *p_demux = (demux_t *)p_this;
    const uint8_t *p_peek;

    CHECK_FILE();
    if(! demux_IsPathExtension( p_demux, ".ram" ) ||
         demux_IsPathExtension( p_demux, ".rm" ) )
        return VLC_EGENERIC;

    /* Many Real Media Files are misdetected */
    if( vlc_stream_Peek( p_demux->s, &p_peek, 4 ) < 4 )
        return VLC_EGENERIC;
    if( !memcmp( p_peek, ".ra", 3 ) || !memcmp( p_peek, ".RMF", 4 ) )
    {
        return VLC_EGENERIC;
    }

    STANDARD_DEMUX_INIT_MSG( "found valid RAM playlist" );
    p_demux->p_sys->psz_prefix = FindPrefix( p_demux );

    return VLC_SUCCESS;
}
Example #3
0
int
attribute_compat_text_section
_IO_old_fsetpos (_IO_FILE *fp, const _IO_fpos_t *posp)
{
  int result;
  CHECK_FILE (fp, EOF);
  _IO_acquire_lock (fp);
  if (_IO_seekpos_unlocked (fp, posp->__pos, _IOS_INPUT|_IOS_OUTPUT)
      == _IO_pos_BAD)
    {
      /* ANSI explicitly requires setting errno to a positive value on
	 failure.  */
#ifdef EIO
      if (errno == 0)
	__set_errno (EIO);
#endif
      result = EOF;
    }
  else
    result = 0;
  _IO_release_lock (fp);
  return result;
}
Example #4
0
File: asx.c Project: Aakash-729/vlc
int Import_ASX( vlc_object_t *p_this )
{
    demux_t *p_demux = (demux_t *)p_this;

    CHECK_FILE();
    if( demux_IsPathExtension( p_demux, ".asx" ) ||
        demux_IsPathExtension( p_demux, ".wax" ) ||
        demux_IsPathExtension( p_demux, ".wvx" ) ||
        (
          ( CheckContentType( p_demux->s, "video/x-ms-asf" ) ||
            CheckContentType( p_demux->s, "audio/x-ms-wax" ) ) && PeekASX( p_demux )
        ) ||
        demux_IsForced( p_demux, "asx-open" ) )
    {
        msg_Dbg( p_demux, "found valid ASX playlist" );
    }
    else
        return VLC_EGENERIC;

    p_demux->pf_control = Control;
    p_demux->pf_demux = Demux;
    return VLC_SUCCESS;
}
Example #5
0
off64_t
ftello64 (_IO_FILE *fp)
{
  _IO_off64_t pos;
  CHECK_FILE (fp, -1L);
  _IO_acquire_lock (fp);
  pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
  if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
    {
      if (fp->_mode <= 0)
	pos -= fp->_IO_save_end - fp->_IO_save_base;
    }
  _IO_release_lock (fp);
  if (pos == _IO_pos_BAD)
    {
#ifdef EIO
      if (errno == 0)
	__set_errno (EIO);
#endif
      return -1L;
    }
  return pos;
}
Example #6
0
//the functions for both procedures...
//--------------------1.get word-list---------------------------
HashMap *load_wordlist(const char *fname)
{
	//lists of the vocabularies
	cout << "---Opening vocab file '" << fname << "'" << endl;
	ifstream ifs;
	ifs.open(fname,ios::in);
	CHECK_FILE(ifs,fname);
	int num=0;
	HashMap *res = new HashMap(CONS_vocab_map_size);
	while (!ifs.eof()){
		string buf;
		ifs >> buf;
		if (buf=="") continue; // HACK
		string* tmp = new string(buf);
		res->insert(pair<string*, int>(tmp, num++));
	}
	if(res->size() != num){
		//sth wrong
		Error("Something wrong with vocab file.");
	}
	cout << "---Done with loading vocab, all is " << num << endl;
	return res;
}
Example #7
0
wchar_t *
fgetws (wchar_t *buf, int n, _IO_FILE *fp)
{
  _IO_size_t count;
  wchar_t *result;
  int old_error;
  CHECK_FILE (fp, NULL);
  if (n <= 0)
    return NULL;
  if (__glibc_unlikely (n == 1))
    {
      /* Another irregular case: since we have to store a NUL byte and
	 there is only room for exactly one byte, we don't have to
	 read anything.  */
      buf[0] = L'\0';
      return buf;
    }
  _IO_acquire_lock (fp);
  /* This is very tricky since a file descriptor may be in the
     non-blocking mode. The error flag doesn't mean much in this
     case. We return an error only when there is a new error. */
  old_error = fp->_IO_file_flags & _IO_ERR_SEEN;
  fp->_IO_file_flags &= ~_IO_ERR_SEEN;
  count = _IO_getwline (fp, buf, n - 1, L'\n', 1);
  /* If we read in some bytes and errno is EAGAIN, that error will
     be reported for next read. */
  if (count == 0 || (_IO_ferror_unlocked (fp) && errno != EAGAIN))
    result = NULL;
  else
    {
      buf[count] = '\0';
      result = buf;
    }
  fp->_IO_file_flags |= old_error;
  _IO_release_lock (fp);
  return result;
}
Example #8
0
int
_IO_new_fgetpos (FILE *fp, __fpos_t *posp)
{
  off64_t pos;
  int result = 0;
  CHECK_FILE (fp, EOF);
  _IO_acquire_lock (fp);
  pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
  if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
    {
      if (fp->_mode <= 0)
	pos -= fp->_IO_save_end - fp->_IO_save_base;
    }
  if (pos == _IO_pos_BAD)
    {
      /* ANSI explicitly requires setting errno to a positive value on
	 failure.  */
      if (errno == 0)
	__set_errno (EIO);
      result = EOF;
    }
  else if ((off64_t) (__typeof (posp->__pos)) pos != pos)
    {
      __set_errno (EOVERFLOW);
      result = EOF;
    }
  else
    {
      posp->__pos = pos;
      if (fp->_mode > 0 && __libio_codecvt_encoding (fp->_codecvt) < 0)
	/* This is a stateful encoding, safe the state.  */
	posp->__state = fp->_wide_data->_IO_state;
    }

  _IO_release_lock (fp);
  return result;
}
Example #9
0
File: ram.c Project: BossKing/vlc
/**
 * Import_RAM: main import function
 * @param p_this: this demux object
 * @return VLC_SUCCESS if everything is okay
 */
int Import_RAM( vlc_object_t *p_this )
{
    demux_t *p_demux = (demux_t *)p_this;
    const uint8_t *p_peek;

    CHECK_FILE();
    if(! demux_IsPathExtension( p_demux, ".ram" ) ||
         demux_IsPathExtension( p_demux, ".rm" ) )
        return VLC_EGENERIC;

    /* Many Real Media Files are misdetected */
    if( vlc_stream_Peek( p_demux->s, &p_peek, 4 ) < 4 )
        return VLC_EGENERIC;
    if( !memcmp( p_peek, ".ra", 3 ) || !memcmp( p_peek, ".RMF", 4 ) )
    {
        return VLC_EGENERIC;
    }

    msg_Dbg( p_demux, "found valid RAM playlist" );
    p_demux->pf_demux = Demux;
    p_demux->pf_control = Control;

    return VLC_SUCCESS;
}
Example #10
0
int
attribute_compat_text_section
_IO_old_fgetpos64 (_IO_FILE *fp, _IO_fpos64_t *posp)
{
  _IO_off64_t pos;
  CHECK_FILE (fp, EOF);
  _IO_acquire_lock (fp);
  pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
  if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
    pos -= fp->_IO_save_end - fp->_IO_save_base;
  _IO_release_lock (fp);
  if (pos == _IO_pos_BAD)
    {
      /* ANSI explicitly requires setting errno to a positive value on
	 failure.  */
#ifdef EIO
      if (errno == 0)
	__set_errno (EIO);
#endif
      return EOF;
    }
  posp->__pos = pos;
  return 0;
}
Example #11
0
int main(int argc, char **argv)
{
	char *infname, *outfname;
	int ret = 0;
	enum { NONE, MACROS, MACROS_WHERE, STATS, DEPS } dump = NONE;
	int i;
	int platform_win32 = 0;
	int freestanding = 0;

	infname = outfname = NULL;

	current_line = 1;
	current_fname = FNAME_BUILTIN;

	macro_add_limits();

	for(i = 0; initial_defs[i].nam; i++){
		if(initial_defs[i].is_fn)
			macro_add_func(initial_defs[i].nam, initial_defs[i].val, NULL, 0, 1);
		else
			macro_add(initial_defs[i].nam, initial_defs[i].val, 0);
	}

	switch(platform_type()){
		case PLATFORM_x86_64:
			macro_add("__LP64__", "1", 0);
			macro_add("__x86_64__", "1", 0);
			/* TODO: __i386__ for 32 bit */
			break;

		case PLATFORM_mipsel_32:
			macro_add("__MIPS__", "1", 0);
	}

	if(platform_bigendian())
		macro_add("__BYTE_ORDER__", "__ORDER_BIG_ENDIAN__", 0);
	else
		macro_add("__BYTE_ORDER__", "__ORDER_LITTLE_ENDIAN__", 0);

	switch(platform_sys()){
#define MAP(t, s) case t: macro_add(s, "1", 0); break
		MAP(PLATFORM_LINUX,   "__linux__");
		MAP(PLATFORM_FREEBSD, "__FreeBSD__");
#undef MAP

		case PLATFORM_DARWIN:
			macro_add("__DARWIN__", "1", 0);
			macro_add("__MACH__", "1", 0); /* TODO: proper detection for these */
			macro_add("__APPLE__", "1", 0);
			break;

		case PLATFORM_CYGWIN:
			macro_add("__CYGWIN__", "1", 0);
			platform_win32 = 1;
			break;
	}

	macro_add("__WCHAR_TYPE__",
			platform_win32 ? "short" : "int", 0);

	macro_add_sprintf("__BIGGEST_ALIGNMENT__", "%u", platform_align_max());

	current_fname = FNAME_CMDLINE;

	for(i = 1; i < argc && *argv[i] == '-'; i++){
		if(!strcmp(argv[i]+1, "-"))
			break;

		switch(argv[i][1]){
			case 'I':
				if(argv[i][2])
					include_add_dir(argv[i]+2);
				else
					goto usage;
				break;

			case 'o':
				if(outfname)
					goto usage;

				if(argv[i][2])
					outfname = argv[i] + 2;
				else if(++i < argc)
					outfname = argv[i];
				else
					goto usage;
				break;

			case 'P':
				option_line_info = 0;
				break;

			case 'C':
				if(argv[i][2] == '\0')
					strip_comments = STRIP_EXCEPT_DIRECTIVE;
				else if(!strcmp(argv[i] + 2, "C"))
					strip_comments = STRIP_NONE;
				break;

			case 'M':
				if(!strcmp(argv[i] + 2, "M")){
					dump = DEPS;
					no_output = 1;
				}else{
					goto usage;
				}
				break;

			case 'D':
			{
				char *arg = argv[i] + 2;
				char *eq;
				char *directive;

				if(!*arg){
					/* allow "-D" "arg" */
					arg = argv[++i];
					if(!arg)
						goto usage;
				}

				/* -D'yo yo' means #define yo yo 1, that is,
				 * we literally generate the #define line */

				eq = strchr(arg, '=');
				if(eq)
					*eq = '\0';

				directive = ustrprintf(
						"define %s %s",
						arg, eq ? eq + 1 : "1");

				parse_internal_directive(directive);
				free(directive);
				break;
			}

			case 'U':
				if(!argv[i][2])
					goto usage;
				macro_remove(argv[i] + 2);
				break;

			case 'd':
				if(argv[i][2] && argv[i][3])
					goto defaul;
				switch(argv[i][2]){
					case 'M':
					case 'S':
					case 'W':
						/* list #defines */
						dump = (
								argv[i][2] == 'M' ? MACROS :
								argv[i][2] == 'S' ? STATS :
								MACROS_WHERE);

						no_output = 1;
						break;
					case '\0':
						option_trace = 1;
						break;
					default:
						goto usage;
				}
				break;

			case '\0':
				/* we've been passed "-" as a filename */
				break;

			case 'f':
				if(!strcmp(argv[i]+2, "freestanding")){
					freestanding = 1;
				}else if(!strncmp(argv[i]+2, "message-length=", 15)){
					const char *p = argv[i] + 17;
					warning_length = atoi(p);
				}else{
					goto usage;
				}
				break;

			case 'W':
			{
				int off;
				unsigned j;
				char *p = argv[i] + 2;

				off = !strncmp(p, "no-", 3);
				if(off)
					p += 3;


				ITER_WARNS(j){
					if(!strcmp(p, warns[j].warn)){
						if(off)
							wmode &= ~warns[j].or_mask;
						else
							wmode |= warns[j].or_mask;
						break;
					}
				}

				/* if not found, we ignore - it was intended for cc1 */
				break;
			}

			case 'O':
			{
				switch(argv[i][2]){
					case '0':
						break;
					case 's':
						macro_add("__OPTIMIZE_SIZE__",  "1", 0);
						/* fallthru */
					default:
						macro_add("__OPTIMIZE__",  "1", 0);
				}
				break;
			}

			case 'w':
				if(!argv[i][2]){
					wmode = 0;
					break;
				}
				/* fall */


			default:
defaul:
				if(std_from_str(argv[i], &cpp_std, NULL) == 0){
					/* we have an std */
				}else if(!strcmp(argv[i], "-trigraphs")){
					option_trigraphs = 1;
				}else if(!strcmp(argv[i], "-digraphs")){
					option_digraphs = 1;
				}else{
					fprintf(stderr, "unrecognised option \"%s\"\n", argv[i]);
					goto usage;
				}
		}
	}

	current_fname = FNAME_BUILTIN;

	macro_add("__STDC_HOSTED__",  freestanding ? "0" : "1", 0);
	switch(cpp_std){
		case STD_C89:
		case STD_C90:
			/* no */
			break;
		case STD_C99:
			macro_add("__STDC_VERSION__", "199901L", 0);
			break;
		case STD_C11:
			macro_add("__STDC_VERSION__", "201112L", 0);
	}

	if(i < argc){
		infname = argv[i++];
		if(i < argc){
			if(outfname)
				goto usage;
			outfname = argv[i++];
			if(i < argc)
				goto usage;
		}
	}

	calctime(infname);

#define CHECK_FILE(var, mode, target) \
	if(var && strcmp(var, "-")){ \
		if(!freopen(var, mode, target)){ \
			fprintf(stderr, "open: %s: ", var); \
			perror(NULL); \
			return 1; \
		} \
	}

	CHECK_FILE(outfname, "w", stdout)
	CHECK_FILE(infname,  "r", stdin)

	if(infname){
		dirname_push(udirname(infname));
	}else{
		infname = "<stdin>";
		dirname_push(ustrdup("."));
	}

	current_fname = infname;

	preprocess();

	if(wmode & WUNUSED)
		macros_warn_unused();

	switch(dump){
		case NONE:
			break;
		case MACROS:
		case MACROS_WHERE:
			macros_dump(dump == MACROS_WHERE);
			break;
		case STATS:
			macros_stats();
			break;
		case DEPS:
			deps_dump(infname);
			break;
	}

	free(dirname_pop());

	errno = 0;
	fclose(stdout);
	if(errno)
		die("close():");

	return ret;
usage:
	fprintf(stderr, "Usage: %s [options] files...\n", *argv);
	fputs(" Options:\n"
				"  -Idir: Add search directory\n"
				"  -Dxyz[=abc]: Define xyz (to equal abc)\n"
				"  -Uxyz: Undefine xyz\n"
				"  -o output: output file\n"
				"  -P: don't add #line directives\n"
				"  -dM: debug output\n"
				"  -dS: print macro usage stats\n"
				"  -MM: generate Makefile dependencies\n"
				"  -C: don't discard comments, except in macros\n"
				"  -CC: don't discard comments, even in macros\n"
				"  -trigraphs: enable trigraphs\n"
				"  -digraphs: enable digraphs\n"
				, stderr);

	{
		unsigned i;
		ITER_WARNS(i)
			fprintf(stderr, "  -W%s: %s\n", warns[i].warn, warns[i].desc);
	}

	return 1;
}
Example #12
0
void put_bytes(FILE *outfile, const unsigned char *buf, size_t byte_count)
{
    size_t bytes_written = fwrite(buf, 1, byte_count, outfile);
    CHECK_FILE(bytes_written != byte_count, outfile, "fwrite");
}
Example #13
0
void get_bytes(FILE *infile, unsigned char *buf, size_t byte_count)
{
    size_t bytes_read = fread(buf, 1, byte_count, infile);
    CHECK_FILE(bytes_read != byte_count, infile, "fread");
}
Example #14
0
int
__ferror_unlocked (FILE *fp)
{
  CHECK_FILE (fp, EOF);
  return _IO_ferror_unlocked (fp);
}
Example #15
0
FindData File::get_find_data(const wstring& file_path) {
  FindData find_data;
  CHECK_FILE(get_find_data_nt(file_path, find_data));
  return find_data;
}
Example #16
0
void File::create_dir(const wstring& file_path) {
  CHECK_FILE(create_dir_nt(file_path));
}
Example #17
0
wint_t
__getwc_unlocked (FILE *fp)
{
  CHECK_FILE (fp, WEOF);
  return _IO_getwc_unlocked (fp);
}
Example #18
0
FILE *
freopen64 (const char *filename, const char *mode, FILE *fp)
{
  FILE *result;
  CHECK_FILE (fp, NULL);
  if (!(fp->_flags & _IO_IS_FILEBUF))
    return NULL;
  _IO_acquire_lock (fp);
  int fd = _IO_fileno (fp);
  const char *gfilename = (filename == NULL && fd >= 0
			   ? fd_to_filename (fd) : filename);
  fp->_flags2 |= _IO_FLAGS2_NOCLOSE;
  _IO_file_close_it (fp);
  _IO_JUMPS_FILE_plus (fp) = &_IO_file_jumps;
  if (_IO_vtable_offset (fp) == 0 && fp->_wide_data != NULL)
    fp->_wide_data->_wide_vtable = &_IO_wfile_jumps;
  result = _IO_file_fopen (fp, gfilename, mode, 0);
  fp->_flags2 &= ~_IO_FLAGS2_NOCLOSE;
  if (result != NULL)
    result = __fopen_maybe_mmap (result);
  if (result != NULL)
    {
      /* unbound stream orientation */
      result->_mode = 0;

      if (fd != -1)
	{
#ifdef O_CLOEXEC
# ifndef __ASSUME_DUP3
	  int newfd;
	  if (__have_dup3 < 0)
	    newfd = -1;
	  else
	    newfd =
# endif
	      __dup3 (_IO_fileno (result), fd,
                      (result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0
                      ? O_CLOEXEC : 0);
#else
# define newfd 1
#endif

#ifndef __ASSUME_DUP3
	  if (newfd < 0)
	    {
	      if (errno == ENOSYS)
		__have_dup3 = -1;

	      __dup2 (_IO_fileno (result), fd);
	      if ((result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0)
		__fcntl (fd, F_SETFD, FD_CLOEXEC);
	    }
#endif
	  __close (_IO_fileno (result));
	  _IO_fileno (result) = fd;
	}
    }
  else if (fd != -1)
    __close (fd);
  if (filename == NULL)
    free ((char *) gfilename);
  _IO_release_lock (fp);
  return result;
}
Example #19
0
void File::move_file(const wstring& file_path, const wstring& new_path, DWORD flags) {
  CHECK_FILE(move_file_nt(file_path, new_path, flags));
}
Example #20
0
void analyze(FILE *infile, long file_length)
{
    unsigned char buf[4];

    /* read header */
    size_t bytes_read = fread(buf, 1, 4, infile);
    CHECK_FILE(bytes_read != 4, infile, "fread");

    /* check header */
    const char LARC_signature[4] = "LARC"; /* intentionally unterminated */
    CHECK_ERROR(memcmp(buf, LARC_signature, sizeof(LARC_signature)),"Missing LARC signature");

    /* get file count */
    bytes_read = fread(buf, 1, 4, infile);
    CHECK_FILE(bytes_read != 4, infile, "fread");
    uint32_t file_count = read_32_le(buf);
    
    printf("%d files\n", file_count);

    /* read file info */
    struct {
        char *name;
        uint32_t size;
        uint32_t offset;
    } *file_info = malloc(sizeof(file_info[0]) * file_count);
    CHECK_ERRNO(file_info == NULL, "malloc");
    for (int i=0; i<file_count; i++)
    {
        /* file name length */
        bytes_read = fread(buf, 1, 2, infile);
        CHECK_FILE(bytes_read != 2, infile, "fread");
        uint16_t name_length = read_16_le(buf);

        /* allocate for name */
        file_info[i].name = malloc(name_length + 1);
        CHECK_ERRNO(file_info[i].name == NULL, "malloc");

        /* load name */
        bytes_read = fread(file_info[i].name, 1, name_length, infile);
        CHECK_FILE(bytes_read != name_length, infile, "fread");
        file_info[i].name[name_length] = '\0';

        /* load size */
        bytes_read = fread(buf, 1, 4, infile);
        CHECK_FILE(bytes_read != 4, infile, "fread");
        file_info[i].size = read_32_le(buf);

        /* load offset */
        bytes_read = fread(buf, 1, 4, infile);
        CHECK_FILE(bytes_read != 4, infile, "fread");
        file_info[i].offset = read_32_le(buf);

    }

    long data_offset = ftell(infile);
    CHECK_ERRNO(data_offset == -1, "ftell");

    /* dump files */
    for (int i=0; i<file_count; i++)
    {
        long file_offset = data_offset + file_info[i].offset;
        printf("%02d: 0x%08" PRIx32 " 0x%08" PRIx32 " %s\n",
                i, (uint32_t)file_offset,
                file_info[i].size, file_info[i].name);
        
        FILE *outfile = fopen(file_info[i].name, "wb");
        CHECK_ERRNO(outfile == NULL, "fopen");

        dump(infile, outfile, file_offset, file_info[i].size);

        CHECK_ERRNO(fclose(outfile) == EOF, "fclose");
    }
}
Example #21
0
bool ReadSettingsFile (Settings& st)
{
    FILE* settings = _wfopen (L"settings.txt", L"r");
    if (!settings)
    {
        ErrorPrintfBoxW (NULL,
                         MB_OK | MB_ICONSTOP,
                         L"Не найден файл настроек (\"settings.txt\")");
        return false;
    }
    wchar_t str[MAX_STRING_LEN] = L"";

    int line = 1;

    LPWSTR startPt = str;
    LPWSTR endPt = startPt;

    READ_WORD (st.caption);

    CHECK_FILE (settings);

    {
        fgetws (str, MAX_STRING_LEN, settings);
        startPt = str;
        endPt = startPt;
        FIND_NEXT_CHAR (startPt, L'"');
        startPt++;
        CHECK_POINTER (startPt);
        endPt = startPt;
        FIND_NEXT_CHAR (endPt, L'"');
        CHECK_POINTER (endPt);
        *endPt = 0;
        if (!wcscmp (startPt, L"White")) st.grayFill = false;
        else
        if (!wcscmp (startPt, L"Gray")) st.grayFill = true;
        else
        {
            ErrorPrintfBoxW (NULL,
                             MB_OK | MB_ICONSTOP,
                             L"Цвет заливки, указанный в файле \"settings.txt\" на строке %d, не соответствует ни одному из заданных",
                             line);
            return false;
        }
        line++;
    }

    {//! Pages
        fgetws (str, MAX_STRING_LEN, settings);
        startPt = str;
        while (!iswdigit (*startPt) &&
                *startPt != EOF &&
                *startPt != L'\n') startPt++;
        CHECK_POINTER (startPt);
        st.pages = _wtoi (str);
        line++;
    }

    CHECK_FILE (settings);

    {//! filenamePart1 & filenamePart2
        fgetws (str, MAX_STRING_LEN, settings);
        startPt = str;
        endPt = startPt;
        while (*startPt == L' ') startPt++;
        CHECK_POINTER (startPt);
        LPWSTR endPt = startPt;
        FIND_NEXT_CHAR (endPt, L'$');
        CHECK_POINTER (endPt);
        *endPt = 0;
        if (endPt - startPt) st.filenamePart1.Set (new wchar_t [endPt - startPt + 1],
                                                   MEMORY_ARRAY);
        wcscpy (st.filenamePart1.data, startPt);
        endPt++;
        startPt = endPt;
        while (*endPt != L' ' &&
               *endPt != L'\n' &&
               *endPt != EOF &&
               *endPt) endPt++;
        *endPt = 0;
        if (endPt - startPt) st.filenamePart2.Set (new wchar_t [endPt - startPt + 1],
                                                   MEMORY_ARRAY);
        wcscpy (st.filenamePart2.data, startPt);
        line++;
    }

    CHECK_FILE (settings);

    READ_WORD (st.notCompletedMessage);

    CHECK_FILE (settings);

    READ_WORD (st.nextPageButton);

    CHECK_FILE (settings);

    READ_WORD (st.doneButton);

    CHECK_FILE (settings);

    READ_WORD (st.buttonFont);

    CHECK_FILE (settings);

    {//! buttonFontSize
        fgetws (str, MAX_STRING_LEN, settings);
        startPt = str;
        while (!iswdigit (*startPt) &&
                *startPt != EOF &&
                *startPt != L'\n') startPt++;
        CHECK_POINTER (startPt);
        st.buttonFontSize = _wtoi (str);
        line++;
    }

    fclose (settings);

    return true;
}
Example #22
0
int
putchar_unlocked (int c)
{
    CHECK_FILE (_IO_stdout, EOF);
    return _IO_putc_unlocked (c, _IO_stdout);
}
Example #23
0
int try_embedded_fsb(FILE *infile)
{
    int rc;
    size_t size_rc;
    long whole_file_size;
    unsigned char search_buf[0x800];
    int gotone = 0;

    printf("\nTrying embedded search...\n");

    /* get file size */
    {
        rc = fseek(infile, 0, SEEK_END);
        CHECK_ERRNO(rc == -1, "seeking to file end");

        whole_file_size = ftell(infile);
        CHECK_ERRNO(whole_file_size == -1, "getting file size");
    }

    /* scan */
    for (long offset=0; offset<whole_file_size; offset+=sizeof(search_buf)-maxheadsize)
    {

        rc = fseek(infile, offset, SEEK_SET);
        CHECK_ERRNO(rc == -1, "seeking for search");
 
        if (offset + sizeof(search_buf) > whole_file_size)
        {
            size_rc = fread(search_buf, 1, whole_file_size-offset, infile);
            CHECK_FILE(size_rc != whole_file_size-offset, infile, "reading for search");
        }
        else
        {
            size_rc = fread(search_buf, 1, sizeof(search_buf), infile);
            CHECK_FILE(size_rc != sizeof(search_buf), infile, "reading for search");
        }

        for (long suboffset=0; suboffset<=sizeof(search_buf)-maxheadsize; suboffset++)
        {
            int32_t fsb_size;
            if (test_fsb_header(search_buf+suboffset,&fsb_size) && offset+suboffset+fsb_size <= whole_file_size)
            {
                /* found! */
                printf("found FSB 0x%08" PRIx32 " size 0x%08" PRIx32 "\n",
                        (uint32_t)(offset+suboffset), (uint32_t)fsb_size);

                gotone = 1;

                /* create filename */
                char name[30];
                snprintf(name,sizeof(name),"embedded_%08" PRIx32 ".fsb",(uint32_t)(offset+suboffset));

                FILE *outfile = fopen(name,"wb");
                CHECK_ERRNO(outfile == NULL, "opening output file");

                copy_bytes(infile, outfile, offset+suboffset, fsb_size);

                rc = fclose(outfile);
                CHECK_ERRNO(rc != 0, "closing output file");

                /* skip the contents */
                offset += fsb_size - (sizeof(search_buf)-maxheadsize);
            }
        }
    }

    return gotone;
}
Example #24
0
void File::remove_dir(const wstring& file_path) {
  CHECK_FILE(remove_dir_nt(file_path));
}
Example #25
0
int try_multistream_fsb(FILE *infile)
{
    int32_t stream_count;
    int32_t table_size;
    int32_t body_size;
    long whole_file_size;
    int32_t header_size;
    size_t size_rc;
    int rc;
    unsigned char header[maxheadsize];
    enum fsb_type_t fsb_type;

    /* get file size */
    {
        rc = fseek(infile, 0, SEEK_END);
        CHECK_ERRNO(rc == -1, "seeking to file end");

        whole_file_size = ftell(infile);
        CHECK_ERRNO(whole_file_size == -1, "getting file size");
    }

    /* read header */
    {
        rc = fseek(infile, 0, SEEK_SET);
        CHECK_ERRNO(rc == -1, "seeking to file start");

        size_rc = fread(header, 1, 4, infile);
        CHECK_FILE(size_rc != 4, infile, "reading magic");

        if (!memcmp(&header[0],fsb3headmagic,4))
        {
            printf("Type: FSB3\n");
            header_size = fsb3headsize;
            fsb_type = fsb3;
        }
        else if (!memcmp(&header[0],fsb4headmagic,4))
        {
            printf("Type: FSB4\n");
            header_size = fsb4headsize;
            fsb_type = fsb4;
        }
        else
        {
            /* couldn't find a valid multistream fsb to unpack */
            return 0;
        }

        /* read the rest of the header */
        size_rc = fread(&header[4], 1, header_size-4, infile);
        CHECK_FILE(size_rc != header_size-4, infile, "reading header");

        stream_count = read32bitLE(&header[4]);
        CHECK(stream_count <= 0, "bad stream count");

        table_size = read32bitLE(&header[8]);
        CHECK(table_size <= 0, "bad table size");
        body_size = read32bitLE(&header[12]);
        CHECK(body_size <= 0, "bad body size");

        printf("Header: 0x%" PRIx32 " bytes\n", (uint32_t)header_size);
        printf("Table:  0x%" PRIx32 " bytes\n", (uint32_t)table_size);
        printf("Body:   0x%" PRIx32 " bytes\n", (uint32_t)body_size);
        printf("------------------\n");

        uint64_t total_size = (uint64_t)header_size +
                (uint64_t)table_size +
                (uint64_t)body_size;
        printf("Total:  0x%" PRIx64 " bytes\n", total_size);
        printf("File:   0x%lx bytes\n", whole_file_size);

        CHECK( whole_file_size < total_size ,
                "file size less than FSB size, truncated?");
        if ( whole_file_size - total_size > 0x800 )
        {
            /* maybe embedded? */
            return 0;
        }

        if (stream_count == 1)
        {
            printf("Already a single stream.\n");
            return 1;
        }

        printf("%" PRId32 " streams\n", stream_count);
    }

    /* copy each stream */
    {
        long table_offset = header_size;
        long body_offset = header_size + table_size;

        static const int max_name = 0x1e;
        static const char fsbext[] = ".fsb";
        int count_digits = ceil(log10(stream_count+2)); /* +1 since we add one, +1 to round up even counts */
        int name_bytes = count_digits + 1 + max_name + sizeof(fsbext);
        char *name_buf = malloc(name_bytes);
        CHECK_ERRNO(name_buf == NULL, "malloc for name buffer");

        for (int i = 0; i < stream_count; i++) {
            int16_t entry_size;
            int16_t padding_size;
            int32_t entry_file_size;
            const int entry_min_size = 0x28;
            unsigned char entry_buf[0x28];
            unsigned char pad_buf[0x10] = {0};
            FILE *outfile;

            rc = fseek(infile, table_offset, SEEK_SET);
            CHECK_ERRNO(rc, "seeking to table entry");

            size_rc = fread(entry_buf, 1, entry_min_size, infile);
            CHECK_FILE(size_rc != entry_min_size, infile,
                    "reading table entry header");

            entry_size = read16bitLE(&entry_buf[0]);
            CHECK(entry_size < entry_min_size, "entry too small");
            padding_size = 0x10 - (header_size + entry_size) % 0x10;

            entry_file_size = read32bitLE(&entry_buf[0x24]);

            /* build the output name */
            memset(name_buf, 0, name_bytes);
            snprintf(name_buf, count_digits+2, "%0*u_",
                    count_digits, (unsigned int)(i+1));
            memcpy(name_buf+count_digits+1, entry_buf+2, max_name);

            /* append .fsb to name */
            memcpy(name_buf+strlen(name_buf),fsbext,sizeof(fsbext));

            printf("%-*s"
                       " header 0x%02" PRIx32
                       " entry 0x%04" PRIx16 " (+0x%04" PRIx16 " padding)"
                       " body 0x%08" PRIx32
                       " (0x%08" PRIx32 ")\n",
                       name_bytes,
                       name_buf,
                       (uint32_t)header_size,
                       (uint16_t)entry_size,
                       (uint16_t)padding_size,
                       (uint32_t)entry_file_size,
                       (uint32_t)body_offset);

            /* open output */
            outfile = fopen(name_buf, "wb");
            CHECK_ERRNO(outfile == NULL, "opening output file");

            /* fill in the header */
            write32bitLE(1, &header[0x4]);
            write32bitLE(entry_size+padding_size, &header[0x8]);
            write32bitLE(entry_file_size, &header[0xc]);

            /* write out the header */
            size_rc = fwrite(header, 1, header_size, outfile);
            CHECK_FILE(size_rc != header_size, outfile, "writing header");

            /* write out the table entry */
            copy_bytes(infile, outfile, table_offset, entry_size);

            /* write out padding */
            if (padding_size) {
                size_rc = fwrite(pad_buf, 1, padding_size, outfile);
                CHECK_FILE(size_rc != padding_size, outfile, "writing pad");
            }

            /* write out the body */
            copy_bytes(infile, outfile, body_offset, entry_file_size);

            /* close */
            rc = fclose(outfile);
            CHECK_ERRNO(rc != 0, "closing output file");

            table_offset += entry_size;
            body_offset += entry_file_size;
            if (entry_file_size & 0x1F) {
                body_offset += 0x20 - (entry_file_size & 0x1F);
            }
        }

        free(name_buf);
    }

    return 1;
}
Example #26
0
FILE *
freopen64 (const char *filename, const char *mode, FILE *fp)
{
  FILE *result = NULL;
  char fdfilename[FD_TO_FILENAME_SIZE];

  CHECK_FILE (fp, NULL);

  _IO_acquire_lock (fp);
  /* First flush the stream (failure should be ignored).  */
  _IO_SYNC (fp);

  if (!(fp->_flags & _IO_IS_FILEBUF))
    goto end;

  int fd = _IO_fileno (fp);
  const char *gfilename
    = filename != NULL ? filename : fd_to_filename (fd, fdfilename);

  fp->_flags2 |= _IO_FLAGS2_NOCLOSE;
  _IO_file_close_it (fp);
  _IO_JUMPS_FILE_plus (fp) = &_IO_file_jumps;
  if (_IO_vtable_offset (fp) == 0 && fp->_wide_data != NULL)
    fp->_wide_data->_wide_vtable = &_IO_wfile_jumps;
  result = _IO_file_fopen (fp, gfilename, mode, 0);
  fp->_flags2 &= ~_IO_FLAGS2_NOCLOSE;
  if (result != NULL)
    result = __fopen_maybe_mmap (result);
  if (result != NULL)
    {
      /* unbound stream orientation */
      result->_mode = 0;

      if (fd != -1 && _IO_fileno (result) != fd)
	{
	  /* At this point we have both file descriptors already allocated,
	     so __dup3 will not fail with EBADF, EINVAL, or EMFILE.  But
	     we still need to check for EINVAL and, due Linux internal
	     implementation, EBUSY.  It is because on how it internally opens
	     the file by splitting the buffer allocation operation and VFS
	     opening (a dup operation may run when a file is still pending
	     'install' on VFS).  */
	  if (__dup3 (_IO_fileno (result), fd,
		      (result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0
		      ? O_CLOEXEC : 0) == -1)
	    {
	      _IO_file_close_it (result);
	      result = NULL;
	      goto end;
	    }
	  __close (_IO_fileno (result));
	  _IO_fileno (result) = fd;
	}
    }
  else if (fd != -1)
    __close (fd);

end:
  _IO_release_lock (fp);
  return result;
}
Example #27
0
FILE *
freopen (const char *filename, const char *mode, FILE *fp)
{
  FILE *result;
  CHECK_FILE (fp, NULL);
  if (!(fp->_flags & _IO_IS_FILEBUF))
    return NULL;
  _IO_acquire_lock (fp);
  int fd = _IO_fileno (fp);
  const char *gfilename = (filename == NULL && fd >= 0
			   ? fd_to_filename (fd) : filename);
  fp->_flags2 |= _IO_FLAGS2_NOCLOSE;
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
  if (&_IO_stdin_used == NULL)
    {
      /* If the shared C library is used by the application binary which
	 was linked against the older version of libio, we just use the
	 older one even for internal use to avoid trouble since a pointer
	 to the old libio may be passed into shared C library and wind
	 up here. */
      _IO_old_file_close_it (fp);
      _IO_JUMPS_FILE_plus (fp) = &_IO_old_file_jumps;
      result = _IO_old_file_fopen (fp, gfilename, mode);
    }
  else
#endif
    {
      _IO_file_close_it (fp);
      _IO_JUMPS_FILE_plus (fp) = &_IO_file_jumps;
      if (_IO_vtable_offset (fp) == 0 && fp->_wide_data != NULL)
	fp->_wide_data->_wide_vtable = &_IO_wfile_jumps;
      result = _IO_file_fopen (fp, gfilename, mode, 1);
      if (result != NULL)
	result = __fopen_maybe_mmap (result);
    }
  fp->_flags2 &= ~_IO_FLAGS2_NOCLOSE;
  if (result != NULL)
    {
      /* unbound stream orientation */
      result->_mode = 0;

      if (fd != -1)
	{
#ifdef O_CLOEXEC
# ifndef __ASSUME_DUP3
	  int newfd;
	  if (__have_dup3 < 0)
	    newfd = -1;
	  else
	    newfd =
# endif
	      __dup3 (_IO_fileno (result), fd,
                      (result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0
                      ? O_CLOEXEC : 0);
#else
# define newfd 1
#endif

#ifndef __ASSUME_DUP3
	  if (newfd < 0)
	    {
	      if (errno == ENOSYS)
		__have_dup3 = -1;

	      __dup2 (_IO_fileno (result), fd);
	      if ((result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0)
		__fcntl (fd, F_SETFD, FD_CLOEXEC);
	    }
#endif
	  __close (_IO_fileno (result));
	  _IO_fileno (result) = fd;
	}
    }
  else if (fd != -1)
    __close (fd);
  if (filename == NULL)
    free ((char *) gfilename);

  _IO_release_lock (fp);
  return result;
}
Example #28
0
_IO_ssize_t
_IO_getdelim(char **lineptr, _IO_size_t *n, int delimiter, _IO_FILE *fp)
{
	_IO_ssize_t result;
	_IO_ssize_t cur_len = 0;
	_IO_ssize_t len;

	if (lineptr == NULL || n == NULL)
	{
		MAYBE_SET_EINVAL;
		return -1;
	}
	CHECK_FILE (fp, -1);
	_IO_acquire_lock(fp);
	if (_IO_ferror_unlocked(fp))
	{
		result = -1;
		goto unlock_return;
	}

	if (*lineptr == NULL || *n == 0)
	{
		*n = 120;
		*lineptr = (char *) malloc(*n);
		if (*lineptr == NULL)
		{
			result = -1;
			goto unlock_return;
		}
	}

	len = fp->_IO_read_end - fp->_IO_read_ptr;
	if (len <= 0)
	{
		if (__underflow(fp) == EOF)
		{
			result = -1;
			goto unlock_return;
		}
		len = fp->_IO_read_end - fp->_IO_read_ptr;
	}

	for (;;)
	{
		_IO_size_t needed;
		char *t;
		t = (char *) memchr((void *) fp->_IO_read_ptr, delimiter, len);
		if (t != NULL)
			len = (t - fp->_IO_read_ptr) + 1;
		if (__glibc_unlikely(len >= SSIZE_MAX - cur_len))
		{
			__set_errno(EOVERFLOW);
			result = -1;
			goto unlock_return;
		}
		/* Make enough space for len+1 (for final NUL) bytes.  */
		needed = cur_len + len + 1;
		if (needed > *n)
		{
			char *new_lineptr;

			if (needed < 2 * *n)
				needed = 2 * *n; /* Be generous. */
			new_lineptr = (char *) realloc(*lineptr, needed);
			if (new_lineptr == NULL)
			{
				result = -1;
				goto unlock_return;
			}
			*lineptr = new_lineptr;
			*n = needed;
		}
		memcpy(*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
		fp->_IO_read_ptr += len;
		cur_len += len;
		if (t != NULL || __underflow(fp) == EOF)
			break;
		len = fp->_IO_read_end - fp->_IO_read_ptr;
	}
	(*lineptr)[cur_len] = '\0';
	result = cur_len;

	unlock_return:
	_IO_release_lock(fp);
	return result;
}
Example #29
0
int
feof_unlocked (_IO_FILE *fp)
{
  CHECK_FILE (fp, EOF);
  return _IO_feof_unlocked (fp);
}
Example #30
0
int
_IO_setvbuf (_IO_FILE *fp, char *buf, int mode, _IO_size_t size)
{
  int result;
  CHECK_FILE (fp, EOF);
  _IO_acquire_lock (fp);
  switch (mode)
    {
    case _IOFBF:
      fp->_IO_file_flags &= ~(_IO_LINE_BUF|_IO_UNBUFFERED);
      if (buf == NULL)
	{
	  if (fp->_IO_buf_base == NULL)
	    {
	      /* There is no flag to distinguish between "fully buffered
		 mode has been explicitly set" as opposed to "line
		 buffering has not been explicitly set".  In both
		 cases, _IO_LINE_BUF is off.  If this is a tty, and
		 _IO_filedoalloc later gets called, it cannot know if
		 it should set the _IO_LINE_BUF flag (because that is
		 the default), or not (because we have explicitly asked
		 for fully buffered mode).  So we make sure a buffer
		 gets allocated now, and explicitly turn off line
		 buffering.

		 A possibly cleaner alternative would be to add an
		 extra flag, but then flags are a finite resource.  */
	      if (_IO_DOALLOCATE (fp) < 0)
		{
		  result = EOF;
		  goto unlock_return;
		}
	      fp->_IO_file_flags &= ~_IO_LINE_BUF;
	    }
	  result = 0;
	  goto unlock_return;
	}
      break;
    case _IOLBF:
      fp->_IO_file_flags &= ~_IO_UNBUFFERED;
      fp->_IO_file_flags |= _IO_LINE_BUF;
      if (buf == NULL)
	{
	  result = 0;
	  goto unlock_return;
	}
      break;
    case _IONBF:
      fp->_IO_file_flags &= ~_IO_LINE_BUF;
      fp->_IO_file_flags |= _IO_UNBUFFERED;
      buf = NULL;
      size = 0;
      break;
    default:
      result = EOF;
      goto unlock_return;
    }
  result = _IO_SETBUF (fp, buf, size) == NULL ? EOF : 0;

unlock_return:
  _IO_release_lock (fp);
  return result;
}