Esempio n. 1
0
enum RECORD_RESULT record_write(struct record_t *record, const char *content, size_t size)
{
    if (NULL == record) {
        fprintf (stderr, "Invalid record in record_flush\n");
        return RECORD_ERROR;
    }

    record_open(record);

    writew_lock(record->fd, 0, SEEK_SET, 0);
    lseek(record->fd, 0, SEEK_END);

    int ret = write(record->fd, content, size);

    un_lock(record->fd, 0, SEEK_SET, 0);

    record_close(record);

    if (-1 == ret) {
        fprintf (stderr, "record_write failed\n");
        return RECORD_ERROR;
    }

    if (debug) fprintf (stderr, "record_write: %s %s\n", record->filename, content);
    return RECORD_SUCCESS;
}
void z_output_stream (void)
{

    flush_buffer ();

    switch ((short) zargs[0]) {

    case  1: ostream_screen = TRUE;
	     break;
    case -1: ostream_screen = FALSE;
	     break;
    case  2: if (!ostream_script) script_open ();
	     break;
    case -2: if (ostream_script) script_close ();
	     break;
    case  3: memory_open (zargs[1], zargs[2], zargc >= 3);
	     break;
    case -3: memory_close ();
	     break;
    case  4: if (!ostream_record) record_open ();
	     break;
    case -4: if (ostream_record) record_close ();
	     break;

    }

}/* z_output_stream */
Esempio n. 3
0
/*
 * Open output file with given extension
 */
static void
open_output(const char *infile, const char *outfile)
{
	if (outfile == NULL) {
		fout = stdout;
		return;
	}

	if (infile != NULL && streq(outfile, infile)) {
		warnx("%s already exists. No output generated", infile);
		crash();
	}
	fout = fopen(outfile, "w");
	if (fout == NULL) {
		warn("unable to open %s", outfile);
		crash();
	}
	record_open(outfile);
}
Esempio n. 4
0
/*
 * Open output file with given extension
 */
static void
open_output(char *infile, char *outfile)
{
    if (outfile == NULL) {
	fout = stdout;
	return;
    }
    if (infile != NULL && streq(outfile, infile)) {
	f_print(stderr, "%s: output would overwrite %s\n", cmdname, infile);
	crash();
    }
    fout = fopen(outfile, "w");
    if (fout == NULL) {
	f_print(stderr, "%s: unable to open ", cmdname);
	perror(outfile);
	crash();
    }
    record_open(outfile);
}
Esempio n. 5
0
FILE *epopen(const char *filename, const char *mode) {
	FILE *tmp = NULL;
	int isread;

	if (gl_secure) {
		pr_warning("prevented: popen(\"%s\"):", filename);
		ErrMsg(ER_SECURE, "");
	}
	isread = ((strchr(mode, 'r')) != NULL);
	tmp = (FILE *) popen((char *) filename, (char *) mode);
	record_open(tmp, filename, mode, IS_PIPE);
	if (tmp == NULL) {
		if (isread) 
			ErrMsg(ER_PREAD, filename);
		else 
			ErrMsg(ER_PWRITE, filename);
	}
	return tmp;
}
Esempio n. 6
0
int bbsfdel_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	char *user = getparm("u");
	if (*user != '\0') {
		char file[HOMELEN];
		sethomefile(file, currentuser.userid, "friends");
		record_t r;
		if (record_open(file, O_RDWR, &r) < 0)
			return BBS_EINTNL;
		override_t key;
		strlcpy(key.id, user, sizeof(key.id));
		override_t *ptr =
				record_search(&r, &key, sizeof(key), lsearch, cmp_override);
		if (ptr != NULL)
			record_delete(&r, ptr, sizeof(*ptr));
		record_close(&r);
	}
	printf("Location: fall\n\n");
	return 0;
}
Esempio n. 7
0
void Processor::z_output_stream() {
	flush_buffer();

	switch ((short) zargs[0]) {
	case  1: ostream_screen = true;
		 break;
	case -1: ostream_screen = false;
		 break;
	case  2: if (!ostream_script) script_open();
		 break;
	case -2: if (ostream_script) script_close();
		 break;
	case  3: memory_open(zargs[1], zargs[2], zargc >= 3);
		 break;
	case -3: memory_close();
		 break;
	case  4: if (!ostream_record) record_open();
		 break;
	case -4: if (ostream_record) record_close();
		 break;
	default:
		break;
	}
}
Esempio n. 8
0
File: post.c Progetto: fbbs/fbbs
static int post_record_open_file(const char *file, record_perm_e rdonly,
		record_t *rec)
{
	return record_open(file, post_record_cmp, sizeof(post_record_t), rdonly,
			rec);
}
Esempio n. 9
0
int
open_history( const char *str_name1, const char *str_name2 )
{
#if defined(NO_LOGGING)
  int iret;

  iret = record_close( &record_game );
  if ( iret < 0 ) { return -1; }

  iret = record_open( &record_game, "game.csa", mode_read_write,
		      str_name1, str_name2 );
  if ( iret < 0 ) { return -1; }

  return 1;
#else
  FILE *pf;
  int i, iret;
  char str_file[SIZE_FILENAME];
  
  if ( record_game.pf != NULL && ! record_game.moves )
    {
      record_game.str_name1[0] = '\0';
      record_game.str_name2[0] = '\0';

      if ( str_name1 )
	{
	  strncpy( record_game.str_name1, str_name1, SIZE_PLAYERNAME-1 );
	  record_game.str_name1[SIZE_PLAYERNAME-1] = '\0';
	}
      
      if ( str_name2 )
	{
	  strncpy( record_game.str_name2, str_name2, SIZE_PLAYERNAME-1 );
	  record_game.str_name2[SIZE_PLAYERNAME-1] = '\0';
	}
      return 1;
    }

  if ( ( ( game_status & flag_nonewlog )
#  if defined(USI)
	 ||  usi_mode != usi_off
#  endif
	 ) && 0 <= record_num )
    {
      iret = record_close( &record_game );
      if ( iret < 0 ) { return -1; }
      
      snprintf( str_file, SIZE_FILENAME, "%s/game%03d.csa",
		str_dir_logs, record_num );
      iret = record_open( &record_game, str_file, mode_read_write,
			  str_name1, str_name2 );
      if ( iret < 0 ) { return -1; }
    }
  else
    {
      iret = file_close( pf_log );
      if ( iret < 0 ) { return -1; }
      
      iret = record_close( &record_game );
      if ( iret < 0 ) { return -1; }
      
      for ( i = 0; i < 999; i++ )
	{
	  snprintf( str_file, SIZE_FILENAME, "%s/game%03d.csa",
		    str_dir_logs, i );
	  pf = file_open( str_file, "r" );
	  if ( pf == NULL ) { break; }
	  iret = file_close( pf );
	  if ( iret < 0 ) { return -1; }
	}
      record_num = i;
      
      snprintf( str_file, SIZE_FILENAME, "%s/n%03d.log",
		str_dir_logs, i );
      pf_log = file_open( str_file, "w" );
      if ( pf_log == NULL ) { return -1; }
      
      snprintf( str_file, SIZE_FILENAME, "%s/game%03d.csa",
		str_dir_logs, i );
      iret = record_open( &record_game, str_file, mode_read_write,
			  str_name1, str_name2 );
      if ( iret < 0 ) { return -1; }
    }
  
  return 1;
#endif
}
Esempio n. 10
0
FILE *efopen(const char *filename, const char *mode) {
/*
 * open file filename, warning with some diagnostics on error
 * return FILE *, error message on error.
 */
	FILE *tmp = NULL;
	int isread, error = 0;
#ifdef HAVE_STAT_H
	struct stat statbuf;
#endif /* HAVE_STAT_H */

	if (filename == NULL)
		ErrMsg(ER_NULL, "efopen()");
	if (filename[0] == '\0')
		ErrMsg(ER_NOFILE, "in function efopen()");
	if ((strchr(mode, '+')))
		ErrMsg(ER_IMPOSVAL, "efopen(): + mode not supported");
	isread = ((strchr(mode, 'r')) != NULL); /* read */

#ifndef NO_STD_IN_OUT
	if (strcmp(filename, "-") == 0) /* stdin/stdout */
		return isread ? stdin : stdout;
#endif

	switch (*filename) {
#ifdef HAVE_POPEN
		case '|': /* pipe */
			return (tmp = epopen(++filename, mode));
#endif
		case '>': /* append */
			if (isread) {
				pr_warning("file: %s", filename);
				ErrMsg(ER_IMPOSVAL, "efopen(): cannot read an append file");
			}
			while (isspace(*(++filename))) /* avoid '> file' to become ' file' */
				;
			mode = "a";
			/* BREAKTHROUGH: */
		default:
			tmp = fopen(filename, mode);
			if (tmp == NULL) {
				error = 1;
				if (! isread) /* try read-opening the thing, to fstat it */
					tmp = fopen(filename, "r");
			}
#ifdef HAVE_STAT_H
			if (tmp && fstat(fileno(tmp), &statbuf) < 0) {
				message("cannot fstat `%s'\n", filename);
				error = 1;
			}
			if (tmp && (statbuf.st_mode & S_IFMT) == S_IFDIR) {
				message("`%s' is a directory\n", filename);
				error = 1;
			}
#endif /* HAVE_STAT_H */
			break;
	}
	if (error == 1) {
		if (isread == 1) 
			ErrMsg(ER_READ, filename);
		else 
			ErrMsg(ER_WRITE, filename);
	}
	record_open(tmp, filename, mode, IS_FILE);
	return tmp;
}