Code Search for Developers
 
 
  

endfile.c from EmStar at Krugle


Show endfile.c syntax highlighted

#include "f2c.h"
#include "fio.h"

#ifdef KR_headers
extern char *strcpy();
extern FILE *tmpfile();
#else
#undef abs
#undef min
#undef max
#include "stdlib.h"
#include "string.h"
#endif

extern char *f__r_mode[], *f__w_mode[];

#ifdef KR_headers
integer f_end(a) alist *a;
#else
integer f_end(alist *a)
#endif
{
	unit *b;
	FILE *tf;

	if(a->aunit>=MXUNIT || a->aunit<0) err(a->aerr,101,"endfile");
	b = &f__units[a->aunit];
	if(b->ufd==NULL) {
		char nbuf[10];
		sprintf(nbuf,"fort.%ld",(long)a->aunit);
		if ((tf = fopen(nbuf, f__w_mode[0])))
			fclose(tf);
		return(0);
		}
	b->uend=1;
	return(b->useek ? t_runc(a) : 0);
}

 static int
#ifdef KR_headers
copy(from, len, to) FILE *from, *to; register long len;
#else
copy(FILE *from, register long len, FILE *to)
#endif
{
	int len1;
	char buf[BUFSIZ];

	while(fread(buf, len1 = len > BUFSIZ ? BUFSIZ : (int)len, 1, from)) {
		if (!fwrite(buf, len1, 1, to))
			return 1;
		if ((len -= len1) <= 0)
			break;
		}
	return 0;
	}

 int
#ifdef KR_headers
t_runc(a) alist *a;
#else
t_runc(alist *a)
#endif
{
	long loc, len;
	unit *b;
	FILE *bf, *tf;
	int rc = 0;

	b = &f__units[a->aunit];
	if(b->url)
		return(0);	/*don't truncate direct files*/
	loc=ftell(bf = b->ufd);
	fseek(bf,0L,SEEK_END);
	len=ftell(bf);
	if (loc >= len || b->useek == 0 || b->ufnm == NULL)
		return(0);
	fclose(b->ufd);
	if (!loc) {
		if (!(bf = fopen(b->ufnm, f__w_mode[b->ufmt])))
			rc = 1;
		if (b->uwrt)
			b->uwrt = 1;
		goto done;
		}
	if (!(bf = fopen(b->ufnm, f__r_mode[0]))
	 || !(tf = tmpfile())) {
#ifdef NON_UNIX_STDIO
 bad:
#endif
		rc = 1;
		goto done;
		}
	if (copy(bf, loc, tf)) {
 bad1:
		rc = 1;
		goto done1;
		}
	if (!(bf = freopen(b->ufnm, f__w_mode[0], bf)))
		goto bad1;
	rewind(tf);
	if (copy(tf, loc, bf))
		goto bad1;
	b->uwrt = 1;
	b->urw = 2;
#ifdef NON_UNIX_STDIO
	if (b->ufmt) {
		fclose(bf);
		if (!(bf = fopen(b->ufnm, f__w_mode[3])))
			goto bad;
		fseek(bf,0L,SEEK_END);
		b->urw = 3;
		}
#endif
done1:
	fclose(tf);
done:
	f__cf = b->ufd = bf;
	if (rc)
		err(a->aerr,111,"endfile");
	return 0;
	}




See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  BUILD
  Notice
  README
  abort_.c
  backspac.c
  c_abs.c
  c_cos.c
  c_div.c
  c_exp.c
  c_log.c
  c_sin.c
  c_sqrt.c
  cabs.c
  close.c
  d_abs.c
  d_acos.c
  d_asin.c
  d_atan.c
  d_atn2.c
  d_cnjg.c
  d_cos.c
  d_cosh.c
  d_dim.c
  d_exp.c
  d_imag.c
  d_int.c
  d_lg10.c
  d_log.c
  d_mod.c
  d_nint.c
  d_prod.c
  d_sign.c
  d_sin.c
  d_sinh.c
  d_sqrt.c
  d_tan.c
  d_tanh.c
  derf_.c
  derfc_.c
  dfe.c
  dolio.c
  dtime_.c
  due.c
  ef1asc_.c
  ef1cmc_.c
  endfile.c
  erf_.c
  erfc_.c
  err.c
  etime_.c
  exit_.c
  f2c.h
  f77_aloc.c
  f77vers.c
  f_init.c
  fio.h
  fmt.c
  fmt.h
  fmtlib.c
  fp.h
  ftell_.c
  getarg_.c
  getenv_.c
  h_abs.c
  h_dim.c
  h_dnnt.c
  h_indx.c
  h_len.c
  h_mod.c
  h_nint.c
  h_sign.c
  hl_ge.c
  hl_gt.c
  hl_le.c
  hl_lt.c
  i77vers.c
  i_abs.c
  i_dim.c
  i_dnnt.c
  i_indx.c
  i_len.c
  i_mod.c
  i_nint.c
  i_sign.c
  iargc_.c
  iio.c
  ilnw.c
  inquire.c
  l_ge.c
  l_gt.c
  l_le.c
  l_lt.c
  lbitbits.c
  lbitshft.c
  lio.h
  lread.c
  lwrite.c
  main.c
  open.c
  pow_ci.c
  pow_dd.c
  pow_di.c