C++ (Cpp) fclose Examples

C++ (Cpp) fclose - 30 examples found. These are the top rated real world C++ (Cpp) examples of fclose extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
void capturaSenial (int nSenial)
{
    printf("En captura seƱal: %u\n",nSenial);
    stop_dt=1;
    stop_pt=1;
    stop_et=1;
    sleep(2);

    if( affinity_export != -1 )
        pthread_join(idHiloExport, NULL);
    if( affinity_dump != -1 )
        pthread_join(idHiloCapture, NULL);
    if( affinity_process != -1 )
        pthread_join(idHiloProcess, NULL);

    //if(nSenial==0)
    {
        fclose(flow_file_txt);
        fclose(flow_file_bin);
        printf("fichero flujos cerrado\n");
        fflush(stdout);

        last_packet_timestamp=0;
        fclose(log_file);
        printf("redes liberadas\n");

        freeIPSessionPool();
        printf("pool sesiones liberado\n");
        freeNodelPool();
        printf("Recursos liberados\nSaliendo...\n");
    }
    return;
}
Example #2
0
/**
 *  Lengthen the file whose name is @param discrepancy_filename by one byte. Or,
 *  do nothing, if @param discrepancy_filename is NULL.
 **/
static int dcc_note_discrepancy(const char *discrepancy_filename)
{
    FILE *discrepancy_file;
    if (!discrepancy_filename) return 0;
    if (!(discrepancy_file = fopen(discrepancy_filename, "a"))) {
        rs_log_error("failed to open discrepancy_filename file: %s: %s",
                     discrepancy_filename,
                     strerror(errno));
        return EXIT_IO_ERROR;
    }
    if (fputc('@', discrepancy_file) == EOF) {
        rs_log_error("failed to write to discrepancy_filename file: %s",
                     discrepancy_filename);
        fclose(discrepancy_file);
        return EXIT_IO_ERROR;
    }
    /* The file position is a property of the stream, so we are
    assured that exactly one process will take the 'if' branch when
    max_discrepancies_before_demotion failures is reached. */
    if (ftell(discrepancy_file) ==
            (long int)dcc_get_max_discrepancies_before_demotion()) {
        rs_log_warning("now using plain distcc, possibly due to "
                       "inconsistent file system changes during build");
    }
    fclose(discrepancy_file);
    return 0;
}
Example #3
0
Network *wt_restore ( char *netname , char *filename , int *errnum )
{
    FILE *fp ;
    Network *net ;

    if ((fp = fopen ( filename , "rb" )) == NULL) {
        *errnum = 1 ;
        return NULL ;
    }

    net = read_header ( netname , fp , errnum ) ;
    if (net == NULL) {
        fclose ( fp ) ;
        return NULL ;
    }

    *errnum = net->wt_restore ( fp ) ;
    fclose ( fp ) ;

    if (*errnum) {  // If file read error or insufficient memory
        MEMTEXT ( "WT_SAVE: file error delete network" ) ;
        net->ok = 1 ;  // Destructor must free memory
        delete net ;
        net = NULL ;
    }
    net->errtype = 1 ;          // Tell other routines net is trained

    return net ;
}
void kodirane()
{
    unsigned short int j, c;
    FILE *input, *output;
    input=fopen("input.txt","r");
    output=fopen("output.txt","w");
    while(!feof(input))
    {
        fread(&current_letter, sizeof(unsigned char), 1, input);
        if(kod_dekod==0)
            current_letter=(unsigned char)rotors[left_rotor][(left_rotor_offset+rotors[center_rotor][(center_rotor_offset+rotors[right_rotor][(right_rotor_offset+plugboard[(int)current_letter-65])%26])%26])%26]+65;
        else
        {
            c=(unsigned short int)current_letter-65;
            for(j=0; rotors[left_rotor][(left_rotor_offset+j)%26]!=c; j++);
            c=j;
            for(j=0; rotors[center_rotor][(center_rotor_offset+j)%26]!=c; j++);
            c=j;
            for(j=0; rotors[right_rotor][(right_rotor_offset+j)%26]!=c; j++);
            c=j;
            for(j=0; plugboard[j]!=c; j++);
            c=j;
            current_letter=(unsigned char)c+65;
        }
        left_rotor_offset++;
        left_rotor_offset%=26;
        center_rotor_offset++;
        center_rotor_offset%=26;
        right_rotor_offset++;
        right_rotor_offset%=26;
        fwrite(&current_letter, sizeof(unsigned char), 1, output);
    }
    fclose(input);
    fclose(output);
}
Example #5
0
/* The configuration file consists of lines of the form:
 *
 * user type bridge count
 *
 * Return the count entry for the calling user if there is one.  Else
 * return -1.
 */
static int get_alloted(char *me, char *intype, char *link)
{
    FILE *fin = fopen(LXC_USERNIC_CONF, "r");
    char *line = NULL;
    char user[100], type[100], br[100];
    size_t len = 0;
    int n = -1, ret;

    if (!fin) {
        fprintf(stderr, "Failed to open %s: %s\n", LXC_USERNIC_CONF,
                strerror(errno));
        return -1;
    }

    while ((getline(&line, &len, fin)) != -1) {
        ret = sscanf(line, "%99[^ \t] %99[^ \t] %99[^ \t] %d", user, type, br, &n);

        if (ret != 4)
            continue;
        if (strcmp(user, me) != 0)
            continue;
        if (strcmp(type, intype) != 0)
            continue;
        if (strcmp(link, br) != 0)
            continue;
        free(line);
        fclose(fin);
        return n;
    }
    fclose(fin);
    if (line)
        free(line);
    return -1;
}
Example #6
0
File: io.c Project: qingl97/ENSEIRB
/*************************************************************************
* This function writes out the partition vectors for a mesh
**************************************************************************/
void WriteMeshPartition(char *fname, int nparts, int ne, idxtype *epart, int nn, idxtype *npart)
{
    FILE *fpout;
    int i;
    char filename[256];

    sprintf(filename,"%s.epart.%d",fname, nparts);

    if ((fpout = fopen(filename, "w")) == NULL)
        errexit("Problems in opening the partition file: %s", filename);

    for (i=0; i<ne; i++)
        fprintf(fpout,"%d\n", epart[i]);

    fclose(fpout);

    sprintf(filename,"%s.npart.%d",fname, nparts);

    if ((fpout = fopen(filename, "w")) == NULL)
        errexit("Problems in opening the partition file: %s", filename);

    for (i=0; i<nn; i++)
        fprintf(fpout,"%d\n", npart[i]);

    fclose(fpout);


}