예제 #1
0
파일: zpty.c 프로젝트: zsh-users/zsh
static void
deleteptycmd(Ptycmd cmd)
{
    Ptycmd p, q;

    for (q = NULL, p = ptycmds; p != cmd; q = p, p = p->next);

    if (p != cmd)
	return;

    if (q)
	q->next = p->next;
    else
	ptycmds = p->next;

    zsfree(p->name);
    freearray(p->args);

    zclose(cmd->fd);

    /* We kill the process group the command put itself in. */

    kill(-(p->pid), SIGHUP);

    zfree(p, sizeof(*p));
}
예제 #2
0
파일: libbpf.c 프로젝트: 020gzh/linux
static int
bpf_object__create_maps(struct bpf_object *obj)
{
	unsigned int i;

	for (i = 0; i < obj->nr_maps; i++) {
		struct bpf_map_def *def = &obj->maps[i].def;
		int *pfd = &obj->maps[i].fd;

		*pfd = bpf_create_map(def->type,
				      def->key_size,
				      def->value_size,
				      def->max_entries);
		if (*pfd < 0) {
			size_t j;
			int err = *pfd;

			pr_warning("failed to create map: %s\n",
				   strerror(errno));
			for (j = 0; j < i; j++)
				zclose(obj->maps[j].fd);
			return err;
		}
		pr_debug("create map: fd=%d\n", *pfd);
	}

	return 0;
}
예제 #3
0
파일: common.c 프로젝트: AMSMM/NJEMU
void file_close(void)
{
	if (rom_fd != -1)
	{
		zclose(rom_fd);
		zip_close();
		rom_fd = -1;
	}
}
예제 #4
0
TinyDictZStream::~TinyDictZStream()
{
    zclose();
    if ( unp_buffer )
        free( unp_buffer );
    if ( chunks )
        delete chunks;
    if ( offsets )
        delete offsets;
}
int
main(int argc, char **argv)
{
    char buffer[1024];
    FILE *in, *out;
    int result;
    int lineno;

    Opt_Parse(argc, argv, options, Opt_Number(options), 0);

    if (version) {
	printVersion(RcsId);
	exit(0);
    }

    in = zopen(inFile, "r");
    if (in == NULL) {
	perror(inFile);
	exit(1);
    }

    out = zopen(outFile, "w");
    if (out == NULL) {
	perror(outFile);
	exit(1);
    }

    lineno = 0;
    while ((numLines == 0 || lineno < numLines) &&
           fgets(buffer, sizeof(buffer), in))
    {
	fputs(buffer, out);
	lineno ++;
    }

    result = zclose(in);
    fprintf(stderr, "zclose(in) = %d\n", result);

    result = zclose(out);
    fprintf(stderr, "zclose(out) = %d\n", result);

    exit(0);
}
예제 #6
0
파일: zfile.c 프로젝트: AMSMM/NJEMU
void zip_close(void)
{
	if (zip_fd != -1) zclose(zip_fd);

	if (zipfile)
	{
		if (zip_mode == ZIP_READOPEN)
			unzClose(zipfile);
		else
			zipClose(zipfile, NULL);
		zipfile = NULL;
	}

	zip_mode = ZIP_NOTOPEN;
}
예제 #7
0
파일: libbpf.c 프로젝트: 020gzh/linux
int bpf_object__unload(struct bpf_object *obj)
{
	size_t i;

	if (!obj)
		return -EINVAL;

	for (i = 0; i < obj->nr_maps; i++)
		zclose(obj->maps[i].fd);

	for (i = 0; i < obj->nr_programs; i++)
		bpf_program__unload(&obj->programs[i]);

	return 0;
}
예제 #8
0
파일: libbpf.c 프로젝트: 020gzh/linux
static void bpf_object__elf_finish(struct bpf_object *obj)
{
	if (!obj_elf_valid(obj))
		return;

	if (obj->efile.elf) {
		elf_end(obj->efile.elf);
		obj->efile.elf = NULL;
	}
	obj->efile.symbols = NULL;

	zfree(&obj->efile.reloc);
	obj->efile.nr_reloc = 0;
	zclose(obj->efile.fd);
	obj->efile.obj_buf = NULL;
	obj->efile.obj_buf_sz = 0;
}
예제 #9
0
파일: zpty.c 프로젝트: zsh-users/zsh
static void
checkptycmd(Ptycmd cmd)
{
    char c;
    int r;

    if (cmd->read != -1 || cmd->fin)
	return;
    if ((r = read(cmd->fd, &c, 1)) <= 0) {
	if (kill(cmd->pid, 0) < 0) {
	    cmd->fin = 1;
	    zclose(cmd->fd);
	}
	return;
    }
    cmd->read = (int) c;
}
예제 #10
0
bool TinyDictZStream::zinit( unsigned char * next_in, unsigned avail_in, unsigned char * next_out, unsigned avail_out )
{
    zclose();
    if ( !zInitialized ) {
        zStream.zalloc    = NULL;
        zStream.zfree     = NULL;
        zStream.opaque    = NULL;
        zStream.next_in   = next_in;
        zStream.avail_in  = avail_in;
        zStream.next_out  = next_out;
        zStream.avail_out = avail_out;
        if (inflateInit2( &zStream, -15 ) != Z_OK ) {
            // zlib initialization failed
            return false;
        }
        zInitialized = true;
    }
	return true;
}
예제 #11
0
파일: tcp.c 프로젝트: zsh-users/zsh
mod_export int
tcp_close(Tcp_session sess)
{
    int err;
    
    if (sess)
    {  
	if (sess->fd != -1)
	{
	    err = zclose(sess->fd);
	    if (err)
		zwarn("connection close failed: %e", errno);
	}
	zts_delete(sess);
	return 0;
    }

    return -1;
}
예제 #12
0
파일: libbpf.c 프로젝트: 020gzh/linux
static void bpf_program__unload(struct bpf_program *prog)
{
	int i;

	if (!prog)
		return;

	/*
	 * If the object is opened but the program was never loaded,
	 * it is possible that prog->instances.nr == -1.
	 */
	if (prog->instances.nr > 0) {
		for (i = 0; i < prog->instances.nr; i++)
			zclose(prog->instances.fds[i]);
	} else if (prog->instances.nr != -1) {
		pr_warning("Internal error: instances.nr is %d\n",
			   prog->instances.nr);
	}

	prog->instances.nr = -1;
	zfree(&prog->instances.fds);
}
예제 #13
0
void /* FUNCTION */ fdWriteFiles ( int * memptr , char * kprefix ,
				   float * userData , int newnpts ,
				   int * nerr )
{

	/* index sacmem for amplitude, phase, group delay,
	   and the impulse response. */
	int fileDescriptor = 0 , hdrindex , xbegin = 0 ,
		 idx, jdx, nlcmem, nlcdsk, nptwr, 
		 unused1 , unused2 , unused3 ;

	char kname[ MCPFN ] , ksuffix[ 3 ][ 6 ] ;

	float *bufout = NULL , *ptr , amph[ 2 ][ 2 * NDATPTS - 2 ] ;	
	void zwabs() ;

	*nerr = 0;

	/* handle strings */
	if ( strlen ( kprefix ) > MCPFN - 4 )
	    kprefix[ MCPFN - 4 ] = '\0' ;
	strcpy ( ksuffix[ 0 ] , ".spec" ) ;
	strcpy ( ksuffix[ 1 ] , ".gd" ) ;
	strcpy ( ksuffix[ 2 ] , ".imp" ) ;

	/* Determine the begin of the impulse */
	for ( ptr = cmmem.sacmem[memptr[ 9 ]] ; *ptr == 0.0 ; ptr++ )
	    xbegin++ ;

	/* fill the amplitude and phase array */
        for ( idx = 0 ; idx < NDATPTS ; idx++ ) {
            amph[ 0 ][ idx ] = cmmem.sacmem[ memptr[ 6 ] ][ idx ] ;
            amph[ 1 ][ idx ] = cmmem.sacmem[ memptr[ 7 ] ][ idx ] ;
        }

        for (  ; idx < 2 * NDATPTS - 2 ; idx++ ) {
            amph[ 0 ][ idx ] =  cmmem.sacmem[ memptr[ 6 ] ][ 2*NDATPTS-idx-2 ] ;
            amph[ 1 ][ idx ] = -cmmem.sacmem[ memptr[ 7 ] ][ 2*NDATPTS-idx-2 ] ;
        }

	/* Allocate block for headers. */
	allamb ( &cmmem, SAC_HEADER_WORDS, &hdrindex , nerr ) ;
	if ( *nerr != 0 )
	    goto L_ERROR ;

	/* null the header */
	for ( idx = 0 ; idx < SAC_HEADER_FLOATS ; idx++ )
	    cmhdr.fhdr[ idx ] = SAC_FLOAT_UNDEFINED ;
	for ( idx = 0 ; idx < SAC_HEADER_INTEGERS ; idx++ )
	    cmhdr.nhdr[ idx ] = SAC_INT_UNDEFINED ;
	for ( idx = 0 ; idx < SAC_HEADER_ENUMS ; idx++ )
	    cmhdr.ihdr[ idx ] = SAC_INT_UNDEFINED ;
	for ( idx = 0 ; idx < SAC_HEADER_STRINGS ; idx++ )
	    strcpy ( kmhdr.khdr[ idx ] , SAC_CHAR_UNDEFINED ) ;

	/* fill some fields. */
	for ( idx = 0 ; idx < 9 ; idx++ )		/* user fields */
	    *( user0 + idx ) = userData[ idx ] ;

	switch ( (int) (*user0 + 0.5) ) {
	    case 1:  strcpy ( kuser0 , "lowpass " ) ;
		     break ;
	    case 2:  strcpy ( kuser0 , "highpass" ) ;
		     break ;
	    case 3:  strcpy ( kuser0 , "bandpass" ) ;
		     break ;
	    case 4:  strcpy ( kuser0 , "bandrej " ) ;
		     break ;
	    default: strcpy ( kuser0 , "-12345  " ) ;
		     break ;
	}

	switch ( (int) (*user1 + 0.5) ) {
	    case 1:  strcpy ( kuser1 , "Butter  " ) ;
		     break ;
	    case 2:  strcpy ( kuser1 , "Bessel  " ) ;
		     break ;
	    case 3:  strcpy ( kuser1 , "C1      " ) ;
		     break ;
	    case 4:  strcpy ( kuser1 , "C2      " ) ;
		     break ;
	    default: strcpy ( kuser1 , "-12345  " ) ;
		     break ;
	}

	fillNZ () ;					/* time fields */

	*begin  = 0.0 ;					/* other fields */
	*sb     = 0.0 ;
	*nvhdr  = 6 ;
	*idep   = IUNKN ;
	*iztype = IB ;
	*leven  = TRUE ;
	*lpspol = TRUE ;
	*lovrok = TRUE ;
	*lcalda = FALSE ;

	for ( jdx = 0 ; jdx < 3 ; jdx++ ) {	/* loop between output files. */
 
	    /* fill other header fields specific to the data */
	    switch ( jdx ) {
		case 0:	aphdr( newnpts ) ;
			nlcmem = memptr[ 6 ] ;
			break ;
		case 1:	gdhdr( newnpts ) ;
			nlcmem = memptr[ 8 ] ;
			break ;
		case 2:	irhdr( newnpts ) ;
			nlcmem = memptr[ 9 ] ;
			break ;
		default: goto L_ERROR ;
	    }

	    /* Get file name */
	    sprintf ( kname , "%s%s" , kprefix , ksuffix[ jdx ] ) ;

	    /* Open file */
	    znfile( &fileDescriptor , kname , MCPFN , "DATA" , 5 , nerr );
	    if ( *nerr )
		goto L_ERROR ;

	    /* Get ready to write header to disk */
	    nlcdsk = 0;
	    nptwr = SAC_HEADER_WORDS_FILE;

	    if ( ( bufout = (float *) malloc ( SAC_HEADER_SIZEOF_FILE) ) == NULL ) {
		*nerr = 301;
		goto L_ERROR ;
	    }

	    /* move header into working memory */
	    /* copy ( (int*) cmhdr.fhdr , (int*) cmmem.sacmem[ hdrindex ] , SAC_HEADER_NUMBERS ); */
	    copy_float( cmhdr.fhdr, cmmem.sacmem[ hdrindex ], SAC_HEADER_NUMBERS );
	    zputc ( kmhdr.khdr[ 0 ] , 9 , (int *)(cmmem.sacmem[ hdrindex ] + SAC_HEADER_NUMBERS), 
		    ( MCPW + 1 ) * SAC_HEADER_STRINGS) ;

	    /* move header into output buffer */
	    map_hdr_out ( cmmem.sacmem[ hdrindex ] , bufout , FALSE) ;

	    /* write the headers */
	    zwabs( (int *)&fileDescriptor, (char *)(bufout), nptwr, (int *)&nlcdsk, (int *)nerr );

	    free(bufout);
	    bufout = NULL ;

	    nlcdsk += nptwr;
	    nptwr = NDATPTS ;

	    /* Write data to disk */

	    switch ( jdx ) {
		case 0:	nptwr = 2 * NDATPTS - 2 ;
		  zwabs ( (int *)&fileDescriptor, (char *)(amph[ 0 ]) , nptwr, (int *)&nlcdsk, (int *)nerr ) ;
		  /* nlcmem = memptr[ 7 ] ; */
		  nlcdsk += nptwr;
		  zwabs ( (int *)&fileDescriptor, (char *)(amph[ 1 ]) , nptwr, (int *)&nlcdsk, (int *)nerr ) ;
		  break ;
		  
	    case 1: zwabs( (int *)&fileDescriptor, (char *)(cmmem.sacmem[nlcmem]), nptwr, (int *)&nlcdsk, (int *)nerr );
	      break ;
	      
	    case 2: zwabs( (int *)&fileDescriptor, (char *)(cmmem.sacmem[nlcmem] + xbegin), nptwr, (int *)&nlcdsk, (int *)nerr );
	      break ;
	    }



	    /* Close file */
	    zclose ( &fileDescriptor , nerr ) ;
	    fileDescriptor = 0 ;
	} /* end for */

L_ERROR:

	if ( *nerr ) {
	    setmsg ( "ERROR" , *nerr ) ;
	    outmsg () ;
	    clrmsg () ;
	}

	if ( cmdfm.ndfl > 0 )
	    getfil ( 1 , TRUE , &unused1 , &unused2 , &unused3 , nerr ) ;

	if ( bufout ) 
	    free ( bufout ) ;
	if ( fileDescriptor ) 
	    zclose ( &fileDescriptor , nerr ) ;
	relamb ( cmmem.sacmem , hdrindex , nerr );
}
예제 #14
0
bool TinyDictZStream::readChunk( unsigned n )
{
    if ( n >= chunkCount )
        return false;
    if ( !unp_buffer ) {
        unp_buffer = (unsigned char *)malloc( sizeof(unsigned char)*chunkLength );
        unp_buffer_size = chunkLength;
    }
    unp_buffer_start = n * chunkLength;

    if ( fseek( f, offsets[ n ], SEEK_SET ) ) {
        printf( "cannot seek to %d position\n", offsets[n] );
        return false;
    }
    unsigned packsz = chunks[n];
    unsigned char * tmp = (unsigned char *)malloc( sizeof(unsigned char) * packsz );

    crc.reset();
    unsigned int bytesRead = readBytes( tmp, packsz );
    unsigned crc1 = crc.get();
    unsigned crc2 = readU32();
    if ( bytesRead != packsz || error ) {
        printf( "error reading packed data\n" );
        free( tmp );
        return false;
    }
    if ( crc1!=crc2  ) {
        printf( "CRC error: real: %08x expected: %08x\n", crc1, crc2 );
        //free( tmp );
        //return false;
    }
    zclose();
    if ( !zinit(tmp, packsz, unp_buffer, unp_buffer_size) ) {
        printf("cannot init deflater\n");
        return false;
    }
    printf("unpacking %d bytes\n", packsz);
    int err = inflate( &zStream,  Z_PARTIAL_FLUSH );
    printf("inflate result: %d\n", err);
    if ( err != Z_OK ) {
        printf("Inflate error %s (%d). avail_in=%d, avail_out=%d \n", zStream.msg, err, (int)zStream.avail_in, (int)zStream.avail_out);
        free( tmp );
        return false;
    }
    if ( zStream.avail_in ) {
        printf("Inflate: not all data read, still %d bytes available\n", (int)zStream.avail_in );
        free( tmp );
        return false;
    }
    unp_buffer_len = unp_buffer_size - zStream.avail_out;

    printf("freeing tmp\n");
    free( tmp );
    printf("done\n");



    if ( n < chunkCount-1 && unp_buffer_len!=chunkLength ) {
        printf("wrong chunk length\n");
        return false; // too short chunk data
    }


    zclose();
    return true;
}
예제 #15
0
void
init_io(void)
{
    long ttpgrp;
    static char outbuf[BUFSIZ], errbuf[BUFSIZ];

#ifdef RSH_BUG_WORKAROUND
    int i;
#endif

/* stdout, stderr fully buffered */
#ifdef _IOFBF
    setvbuf(stdout, outbuf, _IOFBF, BUFSIZ);
    setvbuf(stderr, errbuf, _IOFBF, BUFSIZ);
#else
    setbuffer(stdout, outbuf, BUFSIZ);
    setbuffer(stderr, errbuf, BUFSIZ);
#endif

/* This works around a bug in some versions of in.rshd. *
 * Currently this is not defined by default.            */
#ifdef RSH_BUG_WORKAROUND
    if (cmd) {
	for (i = 3; i < 10; i++)
	    close(i);
    }
#endif

    if (shout) {
	fclose(shout);
	shout = 0;
    }
    if (SHTTY != -1) {
	zclose(SHTTY);
	SHTTY = -1;
    }

    /* Make sure the tty is opened read/write. */
    if (isatty(0)) {
	zsfree(ttystrname);
	if ((ttystrname = ztrdup(ttyname(0))))
	    SHTTY = movefd(open(ttystrname, O_RDWR));
    }
    if (SHTTY == -1 && (SHTTY = movefd(open("/dev/tty", O_RDWR))) != -1) {
	zsfree(ttystrname);
	ttystrname = ztrdup("/dev/tty");
    }
    if (SHTTY == -1) {
	zsfree(ttystrname);
	ttystrname = ztrdup("");
    }

    /* We will only use zle if shell is interactive, *
     * SHTTY != -1, and shout != 0                   */
    if (interact && SHTTY != -1) {
	init_shout();
	if(!shout)
	    opts[USEZLE] = 0;
    } else
	opts[USEZLE] = 0;

#ifdef JOB_CONTROL
    /* If interactive, make the shell the foreground process */
    if (opts[MONITOR] && interact && (SHTTY != -1)) {
	attachtty(GETPGRP());
	if ((mypgrp = GETPGRP()) > 0) {
	    while ((ttpgrp = gettygrp()) != -1 && ttpgrp != mypgrp) {
		sleep(1);
		mypgrp = GETPGRP();
		if (mypgrp == gettygrp())
		    break;
#ifndef __EMX__
		killpg(mypgrp, SIGTTIN);
#endif
		mypgrp = GETPGRP();
	    }
	} else
	    opts[MONITOR] = 0;
    } else
	opts[MONITOR] = 0;
#else
    opts[MONITOR] = 0;
#endif
}
예제 #16
0
파일: driver.c 프로젝트: phoe-nix/NJEMU
int neogeo_check_game(void)
{
    FILE *fp;
    char fname[16], path[MAX_PATH], linebuf[128];
    int i, fd, found = 0, NGH_number;

    neogeo_ngh = 0;
    hack_irq = 0;

    if (neogeo_boot_bios)
    {
        strcpy(game_name, games[99].name);
        game_index = 99;
    }
    else
    {
        strcpy(game_name, default_name);
        game_index = 0;

        sprintf(path, "%sIPL.TMP", launchDir);

        zip_open(game_dir);

        i = zlength("IPL.TXT");

        if ((fd = zopen("IPL.TXT")) == -1)
        {
            zip_close();
            return 0;
        }
        zread(fd, memory_region_cpu1, i);
        zclose(fd);
        zip_close();

        if ((fp = fopen(path, "w")) == NULL)
        {
            return 0;
        }
        fwrite(memory_region_cpu1, 1, i, fp);
        fclose(fp);

        if ((fp = fopen(path, "r")) == NULL)
        {
            sceIoRemove(path);
            return 0;
        }

        while (fgets(linebuf, 127, fp))
        {
            char *strfname = strtok(linebuf, ",\r\n");
            char *strbank  = strtok(NULL, ",\r\n");
            char *stroffs  = strtok(NULL, ",\r\n");
            char *ext;
            int bank, offs;

            if (strfname == NULL || strbank == NULL || stroffs == NULL)
                break;

            sscanf(strbank, "%d", &bank);
            sscanf(stroffs, "%x", &offs);
            ext = strrchr(strfname, '.');

            if (stricmp(ext, ".PRG") == 0 || stricmp(ext, ".ARG") == 0)
            {
                if (!bank && !offs)
                {
                    strcpy(fname, strfname);
                    found = 1;
                    break;
                }
            }
        }
        fclose(fp);

        sceIoRemove(path);

        if (!found) return 0;

        zip_open(game_dir);
        if ((fd = zopen(fname)) == -1)
        {
            zip_close();
            return 0;
        }

        zread(fd, memory_region_cpu1, 0x110);
        zclose(fd);
        zip_close();

        swab(memory_region_cpu1, memory_region_cpu1, 0x110);
        memcpy(neogeo_game_vectors, memory_region_cpu1, 0x100);

        NGH_number = m68000_read_memory_16(0x108);

        for (i = 0; games[i].ngh_number; i++)
        {
            if (games[i].ngh_number == NGH_number)
            {
                game_index = i + 1;
                neogeo_ngh = NGH_number;
                strcpy(game_name, games[i].name);

                if (NGH_NUMBER(0x0243))	// lastbld2
                    hack_irq = 1;

                break;
            }
        }
    }

    neogeo_reset_driver_type();

    return 1;
}