Пример #1
0
/* *** Die Laderoutine *** */
int LoadImg(char *Filename, MFDB *raster)
{
 IMGHEAD *img;
 long Length;
 int fhndl;

 fhndl=Fopen(Filename, 0);
 if(fhndl<0) return(fhndl);
 Length=Fseek(0L, fhndl, 2);
 Fseek(0L, fhndl, 0);
 img=(void *)Mxalloc(Length, 0);
 if( ((signed long)img)==-32L )  img=(void *)Malloc(Length);
 if( (signed long)img<=0L) { Fclose(fhndl); return((int)img); }
 Fread(fhndl, Length, img);		/* IMG einlesen */
 Fclose(fhndl);

 raster->fd_w = img->LineWidth;
 raster->fd_h = img->Lines;
 raster->fd_wdwidth = (raster->fd_w + 15) / 16;
 raster->fd_stand = 1;
 raster->fd_nplanes = img->Planes;

 Length=(long)raster->fd_wdwidth * 2L * raster->fd_h * raster->fd_nplanes;
 raster->fd_addr=(void *)Mxalloc(Length, 0);
 if( ((signed long)raster->fd_addr)==-32L )
   raster->fd_addr=(void *)Malloc(Length);
 if( (signed long)raster->fd_addr<=0L )  return((int)raster->fd_addr);

 Decompress(img, raster->fd_addr);

 Mfree(img);
 return(0);
}
Пример #2
0
static toff_t
_tiffSeekProc(thandle_t fd, off_t off, int whence)
{
	char buf[256];
	long current_off, expected_off, new_off;

	if (whence == SEEK_END || off <= 0)
		return Fseek(off, (int) fd, whence);
	current_off = Fseek(0, (int) fd, SEEK_CUR); /* find out where we are */
	if (whence == SEEK_SET)
		expected_off = off;
	else
		expected_off = off + current_off;
	new_off = Fseek(off, (int) fd, whence);
	if (new_off == expected_off)
		return new_off;
	/* otherwise extend file -- zero filling the hole */
	if (new_off < 0)            /* error? */
		new_off = Fseek(0, (int) fd, SEEK_END); /* go to eof */
	_TIFFmemset(buf, 0, sizeof(buf));
	while (expected_off > new_off) {
		off = expected_off - new_off;
		if (off > sizeof(buf))
			off = sizeof(buf);
		if ((current_off = Fwrite((int) fd, off, buf)) != off)
			return (current_off > 0) ?
			    new_off + current_off : new_off;
		new_off += off;
	}
	return new_off;
}
Пример #3
0
static toff_t
_tiffSizeProc(thandle_t fd)
{
	long pos, eof;

	pos = Fseek(0, (int) fd, SEEK_CUR);
	eof = Fseek(0, (int) fd, SEEK_END);
	Fseek(pos, (int) fd, SEEK_SET);
	return eof;
}
Пример #4
0
void importiere_longname(char *name)
	{
	int fh, i=1;
	unsigned long fsize;
	char *file=NULL, *tmp=NULL, *tmp1;

	fh=open(name, O_RDONLY);
	if(fh>0)
		{
		fsize = Fseek(0, fh, 2);
		Fseek(0, fh, 0);
		tmp = file = calloc(1,fsize+10L);
		memset(file, 0,fsize+10); 
		read(fh, file, fsize);
		close(fh);
		if(strstr(file, "LONGNAME_")!=NULL)
			{
			file += (strstr(file, "LONGNAME_") - file);
			file++;
			tmp1 = file;
			while(strstr(file, "LONGNAME_")!=NULL)
				{
				file += (strstr(file, "LONGNAME_") - file);
				i++;
				file++;
				}
			file = tmp1-1;
			if(alias_name)
				free(alias_name);
			alias_name = calloc(1,i*sizeof(struct _alias));
			alias_name->no = i;
			i = 0;
			while(strstr(file, "LONGNAME_")!=NULL)
				{
				int len;
				file += strlen("LONGNAME_");
				len = (int)strcspn(file, "=")+1;
				alias_name[i].name = calloc(1,len);		memset(alias_name[i].name, 0, len);
				strncpy(alias_name[i].name, file, len-1);
				file += len;
				len = (int)strcspn(file, "\r\n")+1;
				alias_name[i].alias = calloc(1,len);		memset(alias_name[i].alias, 0, len);
				strncpy(alias_name[i].alias, file, len-1);

				file += (strstr(file, "LONGNAME_") - file);
				i++;
				}
			}
		}
	if(tmp)
		free(tmp);
	}
Пример #5
0
/* -------------- */
int load_font_in(char *font_path, int font_nr)
{
register int f_handle;
register long len;
register fontform *fnt_mem, *search;

f_handle = Fopen(font_path, 0);	
if (f_handle > 0)
	{
	len = Fseek(0L, f_handle, 2);
	Fseek(0L, f_handle, 0);

	pic_sub += len + 4;
	if (pic_sub & 1)
		{
		pic_sub--;
		*(long *)(mtext_mem + mtext_mlen - pic_sub) = len + 1;
		}
	else
		*(long *)(mtext_mem + mtext_mlen - pic_sub) = len;

	fnt_mem = (fontform *)(mtext_mem + mtext_mlen - pic_sub + 4);

	Fread(f_handle, len, fnt_mem);
	Fclose(f_handle);

	if ((long)fnt_point[akt_id] > 0)
		vst_unload_fonts(vdi_handle, 1);

	if ((long)fnt_point[akt_id] > 0)
		fnt_mem[0].next = fnt_point[akt_id];
	else
		fnt_mem[0].next = 0;

	fnt_point[akt_id] = fnt_mem;

	fnt_mem[0].id = 99;
	fnt_mem[0].ch_ofst = (int *)((long)fnt_mem[0].ch_ofst + (long)fnt_mem);
	fnt_mem[0].fnt_dta  = (int *)((long)fnt_mem[0].fnt_dta + (long)fnt_mem);

	remove_font(font_nr);

	fnt_mem = fnt_point[akt_id];
	fnt_mem[0].id = font_nr;

	inst_font();

	return(1);
	}

return(0);
}
Пример #6
0
/*----------------------------------------------------------------------------
>  Function Name: RtStatus_t FileRemove(int32_t RecordNumber,int32_t HandleNumber)

   FunctionType:  Reentrant

   Inputs:        1) Record Number
                  2) Handle Number  

   Outputs:       Returns SUCCESS on success else an Error Code 
                   
   Description:   Updates the handle to associate with the file to be deleted and
                  deletes the contents of the file i.e. marks all the clusters occupied by 
	              the file as zero in FAT Table.

<
----------------------------------------------------------------------------*/
RtStatus_t FileRemove(int32_t RecordNumber, int32_t HandleNumber)
{
    RtStatus_t RetValue = SUCCESS;
    uint8_t Buffer[32];
    int32_t ClusterNumber = 0, FileSize;
    HandleTable_t Temp;
    //  int64_t lTemp;

    Temp = Handle[HandleNumber];

    if (Handle[HandleNumber].StartingCluster != 0) {
        if ((RetValue = Fseek(HandleNumber, -DIRRECORDSIZE, SEEK_CUR)))
            return RetValue;
    }

    if (ReadDirectoryRecord(HandleNumber, RecordNumber, Buffer) < 0)
        return ERROR_OS_FILESYSTEM_NO_MATCHING_RECORD;

    if (Handle[HandleNumber].StartingCluster != 0) {
        if ((RetValue = Fseek(HandleNumber, -DIRRECORDSIZE, SEEK_CUR)))
            return RetValue;
    }

    if ((RetValue = DeleteRecord(HandleNumber, RecordNumber)) < 0)
        return RetValue;

    /* Set the Handle to original position */
    if ((RetValue = Fseek(HandleNumber, (RecordNumber * DIRRECORDSIZE), SEEK_SET)) < 0)
        return RetValue;

    FileSize = FSGetDWord(Buffer, DIR_FILESIZEOFFSET);

    // sdk2.6 changed this to left shift instead of right shift. 
    ClusterNumber =
        ((FSGetWord(Buffer, DIR_FSTCLUSLOOFFSET)) | (FSGetWord(Buffer, DIR_FSTCLUSHIOFFSET) << 16));

    if (((FSGetByte(Buffer, DIR_ATTRIBUTEOFFSET)) & DIRECTORY_MODE) == DIRECTORY_MODE)
        FileSize = 0x7fffffff;

    if ((ClusterNumber != 0) && (FileSize) != 0) {
        /* update the handle to associate with the file to be deleted */
        UpdateHandle(HandleNumber, ClusterNumber);

        /* Delete the contents of the file (i.e. Mark all the clusters occupied by 
           the file as zero in FAT Table) */
        if ((RetValue = DeleteContent(HandleNumber, 0)) < 0)
            return RetValue;
    }
    Handle[HandleNumber] = Temp;

    return SUCCESS;
}
Пример #7
0
void main(void)
{   int Hdl;
    void *OldScreen;
    int dummy;
    long i;

/* d‚termine la base line A pour la position souris
*/
    linea_init();

/* charge l'image et la duplique en largeur
*/       
    Hdl=Fopen("MORETA.NEO",0); if (Hdl<0) { appl_exit(); Pterm0(); }
    Fseek(4L,Hdl,0);
    Fread(Hdl,32L,NewPalette);
    Fseek(128L,Hdl,0);
    for (i=0;i<200;i++) 
    {    LINE1 *p=(LINE1 *)&picbuf[0].line[i];
         Fread(Hdl,sizeof(LINE1),p);
         p[1]=p[0];
    }
    Fclose(Hdl);

/* Duplique l'image en hauteur 
*/  
    picbuf[1]=picbuf[0];
         
/* Installe la pallette et sauve l'ancienne
*/
    InsPalette(); 
    
/* Sauve l'adresse de l'‚cran courant
*/  
    OldScreen=GetScreenPtr();

/* Installe la routine de scrolling en VBL
*/
    InsVBL(Scrolling);
    
/* Boucle en attendant un Ctrl-C
*/
    while (1) if (Bconstat(2)<0 && (char)Bconin(2)==3) break;

/* Remet tout en ordre et sort de l…
*/  
    RmvVBL();
    SetScreenPtr(OldScreen);
    SetScroll(0);
    SetLineStride(0);
    RestPalette();
}
Пример #8
0
/*
 *  Returns -1 if an error seeking; otherwise the routine
 *  returns the size of a file in bytes and leaves the file
 *  at the beginning when finished (successful).
 *
 *  This routine assumes FSEEK and FTELL are present on the system.
 */
long int filesize(FILE *fp)
{
      long int fsize;

      if (Fseek(fp, 0L, SEEK_END) != 0) {
        wipoutput(stderr, "Error searching for the end of the file.\n");
        return(-1L);
      }
      fsize = Ftell(fp);
      if (Fseek(fp, 0L, SEEK_SET) != 0) {
        wipoutput(stderr, "Error finding the beginning of the file.\n");
        return(-1L);
      }
      return(fsize);
}
Пример #9
0
/* read the key's value */
int cfg_readValue(FILE *cfg_file,sftpcfg_t config)
{
	char line[LINE_SIZE];
	char src_value[CFG_VALUE_SIZE];
	char dest_value[CFG_VALUE_SIZE];
	char regexp[REGEXP_SIZE];
	int linenum = 0;
	int offset = 0; 
	memset(line,0,sizeof(line));
	memset(src_value,0,sizeof(src_value));
	memset(dest_value,0,sizeof(dest_value));
	memset(regexp,0,sizeof(regexp));
	sprintf(regexp,"%%*[^%c] %c %%s",config.sep_char,config.sep_char);

	offset = cfg_searchKey(cfg_file,config);

	if( offset < 0)
	{
		fprintf(stderr,"'%s' key is not found !\n",config.key);
		exit(1);
	}
	Fseek(cfg_file,offset,SEEK_SET);
	if(fgets(line,LINE_SIZE,cfg_file))
	{
		sscanf(line,regexp,src_value);
		cut_blank(src_value,dest_value);
		/* storage the value */
		strcpy(config.value,dest_value);
		return 0;
	}
	return -1;
}
Пример #10
0
int checkhang()
{
	long ptr[4];
	
	first_init=0;
	
	buffptr(ptr);

#ifdef DEBUG	
	fprintf(stderr,"first_buf=%lx ptr[0]=%lx\n",first_buf,ptr[0]);
#endif

	if(ptr[0]-first_buf < 512)
	{
#ifdef DEBUG
		fprintf(stderr,"init failed, trying again!\n");
		fprintf(stderr,"first_buf=%lx ptr[0]=%lx\n",first_buf,ptr[0]);
#endif
		Fseek(o_filepos,fd,0);
		filepos = o_filepos;
		init_replay();
		return 1;
	}
	return 0;
}
Пример #11
0
static void
pk_glyphs_fn P2C(FILE *, f,  struct font *, fontp)
{
  register struct glyph *g;
  int hppp, vppp;

  if (debug & DBG_PK)
    Printf ("Reading PK pixel file %s\n", fontp->filename);

  /* skip comment */
  Fseek (f, (long) one (f), SEEK_CUR);

  (void) four (f);	/* skip design size */
  (void) four (f);	/* skip checksum */
  hppp = sfour (f);
  vppp = sfour (f);
  if (hppp != vppp && (debug & DBG_PK))
    Printf ("Font has non-square aspect ratio %d:%d\n", vppp, hppp);

  /* Initialize glyph array.  */
  for (g = fontp->glyph; g < fontp->glyph + 256; ++g)
    {
      g->packed_data = NULL;
      g->bitmap.bits = NULL;
      g->bitmap2.bits = NULL;
    }

  /* Read glyph directory (really a pass over the whole file).  */
  for (;;)
    {
      int bytes_left, flag_low_bits;
      unsigned int cc;

      PK_skip_specials (f, fontp);
      if (PK_flag_byte == PK_POST)
	break;
      flag_low_bits = PK_flag_byte & 0x7;
      if (flag_low_bits == 7)
	{
	  bytes_left = four (f);
	  cc = four (f);
	}
      else if (flag_low_bits > 3)
	{
	  bytes_left = ((flag_low_bits - 4) << 16) + two (f);
	  cc = one (f);
	}
      else
	{
	  bytes_left = (flag_low_bits << 8) + one (f);
	  cc = one (f);
	}
      /* Use the (randomly chosen) `x2' field for the flag byte.  */
      fontp->glyph[cc].x2 = PK_flag_byte;
      
      /* Read the bitmap data, but don't unpack it.  */
      fontp->glyph[cc].packed_data = xmalloc (bytes_left);
      Fread (fontp->glyph[cc].packed_data, bytes_left, 1, f);
    }
}
Пример #12
0
VOID spol_gblk(VOID)
{
	BYTE    handle;

#if GEMDOS
	handle = Fopen( (const char *)spol_path, 0x0000 );
#else
	handle = dos_open( spol_path, 0x0000 );
#endif
	if (handle)
	{
#if GEMDOS
		Fseek( spol_fcnt, handle, 0x0000 );
		spol_cntr = (WORD)Fread( handle, SPLSIZE, (VOID *)spol_pbuf );
#else
		dos_lseek( handle, 0x0000, spol_fcnt );
		spol_cntr = dos_read( handle, SPLSIZE, spol_pbuf );
#endif
		if ( spol_cntr != SPLSIZE )
			spol_sts = TRUE;
		spol_fcnt += LW( spol_cntr );
#if GEMDOS
		Fclose( handle );
#else
		dos_close( handle );
#endif
		spol_ptr = spol_bufr;
	}
	else
	{
		spol_sts = TRUE;
		spol_cntr = 0;
	}
}
Пример #13
0
bool textSource::isHTMLtagComing(wint_t ch)
    {
    bool ret = false;
    if(ch != WEOF && ch != 26 && (html_tag.*tagState)(ch) == tag) 
        {
        long curr_pos = Ftell(sourceFile);
        //assert(html_tag.*tagState == &html_tag_class::lt);
        estate Seq = notag;
        do
            {
            ch = Getc(sourceFile);
            if(ch == WEOF || ch == 26)
                {
                Seq = notag;
                break;
                }
            Seq = (html_tag.*tagState)(ch);
            }
        while(Seq == tag || Seq == endoftag_startoftag);
        /*notag,tag,endoftag,endoftag_startoftag*/
        if(Seq == notag)
            { // Not an HTML tag. Backtrack.
            }
        else // endoftag
            { // ch == '>'
            assert(ch == '>');
            tagendpos = Ftell(sourceFile);// position of first char after '>'
            ret = true;
            }
        Fseek(sourceFile,curr_pos,_SEEK_SET);
        }
    return ret;
    }
Пример #14
0
/* num should be greater than or equal to 1 */
int 
RawDocOutput (query_data * qd, u_long num, FILE * Output)
{
  static last_pos = 0;
  static u_char *c_buffer = 0;
  static int buf_len = -1;
  static u_char *uc_buffer = 0;
  u_long pos, len;
  int ULen;

  FetchDocStart (qd, num, &pos, &len);

  if ((int) len > buf_len)
    {
      if (c_buffer)
	{
	  Xfree (c_buffer);
	  Xfree (uc_buffer);
	}
      if (!(c_buffer = Xmalloc (len)))
	return -1;
      if (!(uc_buffer = Xmalloc ((int) (qd->td->cth.ratio * 1.01 *
					len) + 100)))
	return -1;
      buf_len = len;
    }
  if (last_pos != pos)
    Fseek (qd->td->TextFile, pos, 0);
  Fread (c_buffer, 1, len, qd->td->TextFile);
  last_pos = pos + len;
  DecodeText (qd->cd, c_buffer, len, uc_buffer, &ULen);
  fwrite (uc_buffer, ULen, sizeof (u_char), Output);
  return 0;
}
//=============================================================================
//  FUNCTION: DeleteString
// ----------------------------------------------------------------------------
//! This function adds a string to the deleted index file.
//!
//! \param pDBState
//!     Pointer to the DBState structure for the database that is being used.
//! \param StringIndex
//!     This is the index of the string to add to the deleted list.
//!
//! \retval DB_ERROR_NONE
//!     The string index was added to the list of deleted strings.
//! \retval DB_ERROR_CRITICAL
//!     Something went wrong.
//!
//=============================================================================
static _reentrant INT DeleteString(DBState *pDBState, INT StringIndex)
{
    INT RetCode;
    
    //
    // Add this record to the list of deleted records.
    // This seek is necessary since IndexFileAdd() assumes that the file is 
    // at the point where an index can be added.  This will likely go away
    // at some point.
    //
    Fseek(pDBState->hStString_Idx, 
          pDBState->TopRecord.TotalDelStrings * DB_STRING_HANDLE_SIZE, 
          SEEK_SET);

    RetCode = IndexFileAdd(pDBState->hStString_Idx, StringIndex);
    if (RetCode < 0)
    {
        return(RetCode);
    }
    
    pDBState->TopRecord.TotalStrings--;
    pDBState->TopRecord.TotalDelStrings++;
    
    return(DB_ERROR_NONE);
}
Пример #16
0
/*清除摄像头系统信息, 这里把内存的对应的所有数据都保存到了文件中*/ 
void camera_pro_system_close( void )
{
	/*写入配置文件*/
#if 0
	camera_profile_format cmr_file;
	int write_byte = 0;
	
	write_byte = sizeof(preset_point_format)*PRESET_NUM_MAX;
	memcpy( cmr_file.cmr_preset_list, gpresetcmr_list, write_byte );
	camera_profile_fill_check( &cmr_file, PRESET_NUM_MAX );
	// 从头写入
	if( -1 != Fseek( gpreset_fd, 0, SEEK_SET))
	{
		camera_profile_write( gpreset_fd, &cmr_file );
		Fflush( gpreset_fd );
	}
#endif
	/*2016-1-26不能正常关闭*/ 
	if( gpreset_fd != NULL )
	{
		DEBUG_INFO( "============>camera system close Success!<=======" );
		camera_profile_close( gpreset_fd );
		gpreset_fd = NULL;
	}

	DEBUG_INFO( "============>camera system close Success!<=======" );
}
Пример #17
0
static rpmRC replaceSigDigests(FD_t fd, const char *rpm, Header *sigp,
			       off_t sigStart, off_t sigTargetSize,
			       char *SHA1, uint8_t *MD5)
{
    off_t archiveSize;
    rpmRC rc = RPMRC_OK;

    if (Fseek(fd, sigStart, SEEK_SET) < 0) {
	rc = RPMRC_FAIL;
	rpmlog(RPMLOG_ERR, _("Could not seek in file %s: %s\n"),
		rpm, Fstrerror(fd));
	goto exit;
    }

    /* Get payload size from signature tag */
    archiveSize = headerGetNumber(*sigp, RPMSIGTAG_PAYLOADSIZE);
    if (!archiveSize) {
	archiveSize = headerGetNumber(*sigp, RPMSIGTAG_LONGARCHIVESIZE);
    }

    /* Set reserved space to 0 */
    addMacro(NULL, "__gpg_reserved_space", NULL, 0, RMIL_GLOBAL);

    /* Replace old digests in sigh */
    rc = rpmGenerateSignature(SHA1, MD5, sigTargetSize, archiveSize, fd);
    if (rc != RPMRC_OK) {
	rpmlog(RPMLOG_ERR, _("generateSignature failed\n"));
	goto exit;
    }

    if (Fseek(fd, sigStart, SEEK_SET) < 0) {
	rc = RPMRC_FAIL;
	rpmlog(RPMLOG_ERR, _("Could not seek in file %s: %s\n"),
		rpm, Fstrerror(fd));
	goto exit;
    }

    headerFree(*sigp);
    rc = rpmReadSignature(fd, sigp, RPMSIGTYPE_HEADERSIG, NULL);
    if (rc != RPMRC_OK) {
	rpmlog(RPMLOG_ERR, _("rpmReadSignature failed\n"));
	goto exit;
    }

exit:
    return rc;
}
//=============================================================================
//  FUNCTION: IndexFileAdd
// ----------------------------------------------------------------------------
//! Add an entry to the index file.
//!
//! \param FileHandle 
//!     The handle for the index file to use.
//! \param  FileIndex
//!     The index that we are looking to add to the list of indexes.
//!
//! \retval DB_ERROR_CRITICAL
//!     Something really bad happened and we have no way to recover.
//! \retval DB_ERROR_NONE
//!     The index was successfully added to the index file.
//!
//=============================================================================
static _reentrant INT IndexFileAdd(INT FileHandle, INT FileIndex)
{
    INT TempIndex;
    LONG FilePosition;
    LONG lPosition;
    
    //
    // Need to see if this entry has already been deleted.
    //
    FilePosition = Ftell(FileHandle);
    lPosition = FilePosition;
    Fseek(FileHandle, 0, SEEK_SET);

    while (lPosition > 0)
    {
        if (DB_STRING_HANDLE_SIZE != Fread(FileHandle, &TempIndex, 
                    DB_STRING_HANDLE_SIZE, 
                    DEFAULT_MEMORY, -1))
        {
            return(DB_ERROR_CRITICAL);
        }
        if (TempIndex == FileIndex)
        {
            break;
        }
        lPosition -= DB_STRING_HANDLE_SIZE;
    }    

    if (0 == lPosition)
    {
        //
        // Seek back to the original position.
        //
        Fseek(FileHandle, FilePosition, SEEK_SET);

        //
        // Update deleted list.
        //
        if (DB_STRING_HANDLE_SIZE != Fwrite(FileHandle, &FileIndex, 
                DB_STRING_HANDLE_SIZE, 
                DEFAULT_MEMORY, -1))
        {
            return(DB_ERROR_CRITICAL);
        }
    }
    return(DB_ERROR_NONE);
}
Пример #19
0
long
#else
int
#endif
__write (int fd, const void *buf, size_t size)
{
	unsigned char c, *foo;
	unsigned flags;
	long r;
	struct xattr statbuf;
	_DOSTIME timebuf;

	if (__mint == 0 && isatty(fd)) {
		r = __OPEN_INDEX(fd);
		if (r < 0 || r >= __NHANDLES)
			r = __NHANDLES - 1;
		flags = __open_stat[r].flags;
		if ((flags & RAW) || _sig_handler[SIGINT] != SIG_DFL) {
			foo = (unsigned char *) buf;
			r = size;
			while (r-- > 0) {
				c = *foo++;
				if (c == '\n' && (flags & CRMOD))
					_console_write_byte(fd, '\r');
				_console_write_byte(fd, c);
			}
			return size;
		}
	}

	r = Fwrite(fd, size, buf);
	if (r < 0) {
		__set_errno (-r);
		return -1;
	}
	if (size && r == 0) {
	  if (__mint >= 9)
	    {
	      if ((r = Fcntl (fd, &statbuf, FSTAT)) < 0)
		{
		  __set_errno (-r);
		  return -1;
		}
	      if (((mode_t) statbuf.st_mode & S_IFMT) == S_IFREG)
		{
		  __set_errno (ENOSPC);
		  return -1;
		}
	    }
	  else if (Fdatime (&timebuf, fd, 0) == 0
		   && Fseek (0L, fd, SEEK_CUR) >= 0)
	    {
	      __set_errno (ENOSPC);
	      return -1;
	    }
	}

	return r;
}
Пример #20
0
Файл: pack.c Проект: nforro/rpm
static rpmRC fdJump(FD_t fd, off_t offset)
{
    if (Fseek(fd, offset, SEEK_SET) < 0) {
	rpmlog(RPMLOG_ERR, _("Could not seek in file %s: %s\n"),
		Fdescr(fd), Fstrerror(fd));
	return RPMRC_FAIL;
    }
    return RPMRC_OK;
}
Пример #21
0
/* search the key and return it's offset 
 * in the file if succeed.*/
int cfg_searchKey(FILE *fp,sftpcfg_t config)
{
	char src_key[CFG_KEY_SIZE];
	char dest_key[CFG_KEY_SIZE];
	char line[CFG_VALUE_SIZE];
	char regexp[REGEXP_SIZE];
	int offset = 0;
	int len = 0;
	
	memset(line,0,sizeof(line));
	memset(src_key,0,sizeof(src_key));
	memset(dest_key,0,sizeof(dest_key));
	memset(regexp,0,sizeof(regexp));

	sprintf(regexp,"%%[^%c]",config.sep_char);
	long curr_offset = 0;
	curr_offset = ftell(fp);

	/* make sure seek from the head of file */
	Fseek(fp,0,SEEK_SET);
	while(fgets(line,LINE_SIZE,fp))
	{
		len = strlen(line);	
		offset += len;
		/* skip comments */
		if(is_comment(line,config.comment_char))
		{
				continue;
		}
		sscanf(line,regexp,src_key);	
		cut_blank(src_key,dest_key);
		if(strcmp(dest_key,config.key) == 0)
		{
			Fseek(fp,curr_offset,SEEK_SET);
			/* back to the head of line */
			offset -= len;
			return offset;	
		}
	memset(dest_key,0,sizeof(dest_key));
	}
	Fseek(fp,curr_offset,SEEK_SET);
	return -1;
}
void _reentrant SyncSMVFrame(void)
{
    DWORD dw_time, dw_SkipJpegBlock;
    LONG dwCurrentTime;

	//read the current RTC
   	stc_dwCurrentTime = ReadRTC() * 1000;
    if( stc_iHandle != -1)
    {
		//calculate the current time from audio decoder
        dw_time = ((DWORD)g_wSongByteTotalHigh << 24) + (DWORD)g_wSongByteTotalLow;
        dw_time *= (DWORD)1000000;
        dw_time /= (DWORD)g_SmvWave_dwAvgBytesPerSec;      // Elapsed time in us

		//find the nearest JPEG block to the current point of audio decoder
		//the next JPEG block is preferred to the previous block
		//since frame drop within one JPEG block is time consuming

		//If more preference for the next block, increase the value added to dw_time in the following equation
        dw_SkipJpegBlock = (dw_time + (DWORD)((stc_iDurationInJpegBlock * 6) / 10)) / (DWORD)stc_iDurationInJpegBlock;
		if( (dw_SkipJpegBlock * (DWORD)stc_iDurationInJpegBlock) >= dw_time )
		{
			//the next block is selected. Adjust the LastTime to the starting point of next JPEG block
			stc_dwLastTime = stc_dwCurrentTime + ((dw_SkipJpegBlock * (DWORD)stc_iDurationInJpegBlock) - dw_time);
		}
		else
		{
			//the previous block is selected. Adjust the LastTime to the starting point of previous JPEG block.
			//Then, we use frame drop machanism to fine tune the synchronization
			stc_dwLastTime = stc_dwCurrentTime - (dw_time - (dw_SkipJpegBlock * (DWORD)stc_iDurationInJpegBlock));
		}
		//update the number of frame leave for rendering
        stc_dwTotalFrame = stc_dwTotalFrameBackup - dw_SkipJpegBlock * (DWORD)stc_iFrameInJpegBlock;
		//this is the file offset for the selected JPEG block
        dw_SkipJpegBlock = (dw_SkipJpegBlock * stc_iByteinJpegBlock) + stc_dwVideoStart;
        Fseek( stc_iHandle, dw_SkipJpegBlock, SEEK_SET);

		//initialize JPEG decoder the the selected JPEG block
		SmvCurrentJpeg.iHandle = stc_iHandle;
		SmvCurrentJpeg.DisplayParams.x = 0;
		SmvCurrentJpeg.DisplayParams.y = 0;
		SmvCurrentJpeg.DecParams.output_image_width = stc_iVideoWidth;
		SmvCurrentJpeg.DecParams.output_image_height = stc_iFrameHeight*stc_iFrameInJpegBlock;
		SMV_InitDecoder();

    }
    else
	{
		//??
        stc_dwLastTime = stc_dwCurrentTime - stc_iFrameDuration;
    }

	stc_iNumFrameStop = 0;

}
Пример #23
0
int SourceSeek(InputSource s, int offset)
{
    s->line_length = 0;
    s->next = 0;
    s->seen_eoe = 0;
    s->bytes_consumed = s->bytes_before_current_line = offset;
    s->nextin = s->insize = 0;
    /* XXX line number will be wrong! */
    s->line_number = -999999;
    return Fseek(s->file16, offset, SEEK_SET);
}
Пример #24
0
long x_seek(long offset, int handle, int seekmode)
{
	long result;

#if USE_gemdos
	result = gemdos(66, offset, handle, seekmode);
#else
	result = Fseek(offset, handle, seekmode);
#endif

	return (result < 0) ? (long) xerror((int) result) : result;
}
Пример #25
0
void vflsh()
{
VPAGE *vp;
VPAGE *vlowest;
long addr;
VFILE *vfile;
int x;
for(vfile=vfiles.link.next;
    vfile!=&vfiles;
    vfile=vfile->link.next)
 {
 loop:
 addr= MAXLONG;
 vlowest=0;
 for(x=0;x!=HTSIZE;x++)
  for(vp=htab[x];vp;vp=vp->next)
   if(vp->addr<addr && vp->dirty && vp->vfile==vfile && !vp->count)
    addr=vp->addr, vlowest=vp;
 if(vlowest)
  {
/*  if(!vfile->name) vfile->name=mktmp("/tmp/"); */  /* changed p,w. wong */

  char *pwstring="c:/joe";
  
  if (getenv("JOERC")) pwstring = getenv("JOERC");
  if(!vfile->name) vfile->name=mktmp(pwstring); 
  if(!vfile->fd)
   {
   vfile->fd=Fopen(vfile->name);
   }
  Fseek(vfile->fd,addr);
  if(addr+PGSIZE>vsize(vfile))
   {
   Fwrite(vfile->fd,vlowest->data,(int)(vsize(vfile)-addr));
   vfile->size=vsize(vfile);
   }
  else
   {
   Fwrite(vfile->fd,vlowest->data,PGSIZE);
   if(addr+PGSIZE>vfile->size) vfile->size=addr+PGSIZE;
   }
  vlowest->dirty=0;
  goto loop;
  }
 }
}
Пример #26
0
/*----------------------------------------------------------------------------
>  Function Name: RtStatus_t DeleteTree(uint8_t *filePath)

   FunctionType:  Reentrant

   Inputs:        1) Pointer to the directory path

   Outputs:       Returns 0 on success else an error code
                   
   Description:   Deletes all the files and directories of the specified path
<
----------------------------------------------------------------------------*/
RtStatus_t DeleteTree(uint8_t * filePath)
{
    RtStatus_t RetValue = SUCCESS;
    int32_t HandleNumber = 0;
    int32_t StartingCluster;
    FindData_t _finddata;
    uint8_t Buf[32];
    HandleTable_t TempHandle;
//  int64_t lTemp;

    if ((RetValue = Chdir(filePath)) < 0)
        return RetValue;

    TempHandle = Handle[CWD_HANDLE];

    if ((HandleNumber = Searchfreehandleallocate()) < 0)
        return (RtStatus_t) HandleNumber;

    Handle[HandleNumber] = Handle[CWD_HANDLE];

    if ((Handle[HandleNumber].StartingCluster) ==
        MediaTable[Handle[HandleNumber].Device].RootdirCluster)
        return ERROR_OS_FILESYSTEM_DIR_NOT_REMOVABLE;

    if ((ReadDirectoryRecord(HandleNumber, 1, Buf)) <= 0)
        return ERROR_OS_FILESYSTEM_INVALID_RECORD_NUMBER;

    // sdk 2.6 first corrected the shift direction to left instead of right.  3.095 release had left since it had fix from sdk2.6.
    StartingCluster =
        ((FSGetWord(Buf, DIR_FSTCLUSLOOFFSET)) | (FSGetWord(Buf, DIR_FSTCLUSHIOFFSET) << 16));

    if ((RetValue = Fseek(HandleNumber, 0, SEEK_SET)) < 0)
        return RetValue;

    Freehandle(HandleNumber);

    if ((RetValue =
         DeleteAllRecords(StartingCluster, &_finddata)) == ERROR_OS_FILESYSTEM_DIR_NOT_REMOVABLE) {
        Handle[CWD_HANDLE] = TempHandle;
        return SUCCESS;
    } else {
        Handle[CWD_HANDLE] = TempHandle;
        return RetValue;
    }
}
Пример #27
0
main()
{
	char buf[80];
	const char *str = "AAAAAAAAAAAAAAAAAAAA";
	long fh;
	
	printf("\nVilken fil:");
	gets(buf);
	
	if((fh = Fopen(buf,O_RDWR)) < 0){
		printf("\nKan ej ”ppna filen !");
		exit(1);
	}
	
	Fseek(10L,fh,SEEK_SET);
	
	Fwrite(fh,20,str);
	
	Fclose(fh);
}
Пример #28
0
bool wp_open(char *name)
{
	long	err;

	if (strcmp(name, "PRN:") == 0)
		prn_hdl = -3;
	else if (strcmp(name, "AUX:") == 0)
		prn_hdl = -2;
	else
	{
		err = Fopen(name, 1);
		if (err == -33)
			err = Fcreate(name, 0);
		else if (err > 0)
		{
			prn_hdl = (int) err;
			Fseek(0, prn_hdl, 2);
		}
	}
	return (prn_hdl > -31);
}
Пример #29
0
int mg_get_raw_doc(void *qd, u_long docnum, unsigned char **p_ucbuf, 
		    int *p_ucbuf_len, int *p_retlen)
{
  query_data *real_qd ;
  static last_pos = 0 ;
  static u_char *c_buffer = NULL ;
  u_long pos, len ;
  int newucbuf_len ;
  int temp_retlen, temp_ucbuf_len ;

  if (p_retlen == NULL) p_retlen = &temp_retlen ;
  if (p_ucbuf_len == NULL) {
    p_ucbuf_len = &temp_ucbuf_len ;
    *p_ucbuf_len = 0 ;
  }

  real_qd = (query_data *)qd ;
  FetchDocStart(real_qd, docnum, &pos, &len) ;
  newucbuf_len = (int)(real_qd->td->cth.ratio * 1.01 * len)+101 ;

  if (c_buffer != NULL)
    Xfree(c_buffer) ;
  if (!(c_buffer = Xmalloc(len)))
    return -1 ;

  if (newucbuf_len > *p_ucbuf_len) {
    if (*p_ucbuf != NULL) 
      Xfree(*p_ucbuf) ;
    if (!(*p_ucbuf = Xmalloc(newucbuf_len))) 
      return -1 ;
    *p_ucbuf_len = newucbuf_len ;
  }
  if (last_pos != pos)
    Fseek(real_qd->td->TextFile, pos, 0) ;
  Fread(c_buffer, 1, len, real_qd->td->TextFile) ;
  last_pos = pos+len ;
  DecodeText(real_qd->cd, c_buffer, len, *p_ucbuf, p_retlen) ;
  (*p_ucbuf)[*p_retlen]='\0' ;
  return 0 ;
}
Пример #30
0
static PyObject *rpmfd_seek(rpmfdObject *s, PyObject *args, PyObject *kwds)
{
    char *kwlist[] = { "offset", "whence", NULL };
    off_t offset;
    int whence = SEEK_SET;
    int rc = 0;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "L|i", kwlist, 
				     &offset, &whence)) 
	return NULL;

    if (s->fd == NULL) return err_closed();

    Py_BEGIN_ALLOW_THREADS
    rc = Fseek(s->fd, offset, whence);
    Py_END_ALLOW_THREADS
    if (rc < 0 || Ferror(s->fd)) {
	PyErr_SetString(PyExc_IOError, Fstrerror(s->fd));
	return NULL;
    }
    Py_RETURN_NONE;
}