Example #1
0
/*
 * Return 0 if the files are different, 1 if the files are the same.
 */
static int compare_file(const char *outfn, const char *newfn)
{
	FILE	*old_f, *new_f;
	char	oldbuf[2048], newbuf[2048], *oldcp, *newcp;
	int	retval;

	old_f = fopen(outfn, "r");
	if (!old_f)
		return 0;
	new_f = fopen(newfn, "r");
	if (!new_f) {
		fclose(old_f);
		return 0;
	}

	while (1) {
		oldcp = fgets(oldbuf, sizeof(oldbuf), old_f);
		newcp = fgets(newbuf, sizeof(newbuf), new_f);
		if (!oldcp && !newcp) {
			retval = 1;
			break;
		}
		if (!oldcp || !newcp || strcmp(oldbuf, newbuf)) {
			retval = 0;
			break;
		}
	}
	fclose(old_f);
	fclose(new_f);
	return retval;
}
Example #2
0
void read_rates(HRATEEFF *rate_table){

   FILE *fA = fopen(ALPHA_FILE, "r");
   FILE *fR = fopen(RR_FILE, "r"); 

   unsigned i, j, l;

   maketab(log(TR_MIN), log(TR_MAX), NTR, rate_table->logTR_tab);
   maketab(TM_TR_MIN, TM_TR_MAX, NTM, rate_table->TM_TR_tab);
   rate_table->DlogTR = rate_table->logTR_tab[1] - rate_table->logTR_tab[0];
   rate_table->DTM_TR = rate_table->TM_TR_tab[1] - rate_table->TM_TR_tab[0];  

   for (i = 0; i < NTR; i++) {  
      for (j = 0; j < NTM; j++) {  
	 for (l = 0; l <= 1; l++) {
           fscanf(fA, "%le", &(rate_table->logAlpha_tab[l][j][i]));
           rate_table->logAlpha_tab[l][j][i] = log(rate_table->logAlpha_tab[l][j][i]);
        }
      }
    
      fscanf(fR, "%le", &(rate_table->logR2p2s_tab[i]));
      rate_table->logR2p2s_tab[i] = log(rate_table->logR2p2s_tab[i]);
      
   }
   fclose(fA);
   fclose(fR);
}
Example #3
0
void
lostpeer(int ignore)
{
	(void)ignore;

	if (connected) {
		if (cout != NULL) {
			shutdown(fileno(cout), 1+1);
			fclose(cout);
			cout = NULL;
		}
		if (data >= 0) {
			shutdown(data, 1+1);
			close(data);
			data = -1;
		}
		connected = 0;
	}
	pswitch(1);
	if (connected) {
		if (cout != NULL) {
			shutdown(fileno(cout), 1+1);
			fclose(cout);
			cout = NULL;
		}
		connected = 0;
	}
	proxflag = 0;
	pswitch(0);
}
void saveKeyMappings()
{
	FILE *ff = fopen(KEYMAPPINGS_FILE, "w");
	if( !ff )
		return;
	for( std::map<int, int>::const_iterator it = keyMappings.begin(); it != keyMappings.end(); it++ )
		fprintf(ff, "%d=%d\n", it->first, it->second);
	fclose(ff);
	ff = fopen(KEYMAPPINGS_CTRL_FILE, "w");
	if( !ff )
		return;
	for( std::set<int>::const_iterator it = keyMappingsCtrl.begin(); it != keyMappingsCtrl.end(); it++ )
		fprintf(ff, "%d\n", *it);
	fclose(ff);
	ff = fopen(KEYMAPPINGS_SHIFT_FILE, "w");
	if( !ff )
		return;
	for( std::set<int>::const_iterator it = keyMappingsShift.begin(); it != keyMappingsShift.end(); it++ )
		fprintf(ff, "%d\n", *it);
	fclose(ff);
	ff = fopen(KEYMAPPINGS_ALT_FILE, "w");
	if( !ff )
		return;
	for( std::set<int>::const_iterator it = keyMappingsAlt.begin(); it != keyMappingsAlt.end(); it++ )
		fprintf(ff, "%d\n", *it);
	fclose(ff);
}
Example #5
0
File: test.c Project: matsimon/RA
/* printf memory */
void test_printf_memory_write() {
    byte buf[4];
    word w = 'a' << 24 | 'b'<<16 | 'c'<<8 | '\n';

    /* set up a testfile in write mode */
    FILE *file = fopen(TESTFILE,"w");
    assert(file);

    /* redirect output of fprintf memory to this file */
    outputStream = file;

    /* write the string "abc" to fprintf */
    S2 = FPRINTF_MEMORY_LOCATION;
    S1 = w;
    test_execute(create_itype_hex(0x000, I_S1, I_S2, OC_SW));
    fclose(file);

    /* check if the output was "abc" */
    file = fopen(TESTFILE,"r");
    assert(file);
    fread(buf, 1, 4, file);
    fclose(file);
    assert(buf[0] == 'a');
    assert(buf[1] == 'b');
    assert(buf[2] == 'c');
    assert(buf[3] == '\n');
}
Example #6
0
int main(int argc, char *argv[])
{
    if (argc < 2) {
        printf("Supply the disk dump as a parameter!\n");
        return -1;
    }
    char* filename = argv[1];
    FILE *fp = fopen(filename, "rb");
    if (fp == NULL) {
        printf("Cannot open file\n");
        return -1;
    }

    if (is_infected(fp)) {
        printf("[+] Petya FOUND on the disk!\n");
    } else {
        printf("[-] Petya not found on the disk!\n");
    }
    printf("---\n");

    if (stage1(fp) == 0) {
        printf("[OK] Stage 1 key recovered!\n");
        fclose(fp);
        return 0;
    }

    printf("Invalid Stage1 key! Probably the key has been already erased!\n");
    printf("Try to recover from Stage2 by third-party decoder!\n");
    printf("Paste the data you got below on one of the following sites:\n");
    printf("+ https://petya-pay-no-ransom.herokuapp.com/\n");
    printf("+ https://petya-pay-no-ransom-mirror1.herokuapp.com/\n");
    stage2(fp);
    fclose(fp);
    return 0;
}
static int check_tty ( const char *tty )
{
	FILE *fp;
	int i;
	char buf[BUFSIZ];

	if (( fp = fopen ( bb_path_securetty_file, "r" ))) {
		while ( fgets ( buf, sizeof( buf ) - 1, fp )) {
			for ( i = bb_strlen( buf ) - 1; i >= 0; --i ) {
				if ( !isspace ( buf[i] ))
					break;
			}
			buf[++i] = '\0';
			if (( buf [0] == '\0' ) || ( buf [0] == '#' ))
				continue;

			if ( strcmp ( buf, tty ) == 0 ) {
				fclose ( fp );
				return 1;
			}
		}
		fclose(fp);
		return 0;
	}
	/* A missing securetty file is not an error. */
	return 1;
}
Example #8
0
File: Road.c Project: rmnsfx/Pion
s8 rod_INIT(void)
{
	char temp[20];	
	
	pRFile = NULL;
	
	pRFile = fopen ("Road.log","r");
	
	if (pRFile != 0)
	{
		
		fscanf(pRFile, "%s", temp);			
		
		fclose(pRFile);	
				
		pRFile = fopen (temp,"r");		
		
		if (pRFile != 0) 
		{
			fclose(pRFile);	
			return 0;
		}
		else return -1;
	}
	else return -1;
}
Example #9
0
void done(int k)
{
    if (action_file) { fclose(action_file); unlink(action_file_name); }
    if (text_file) { fclose(text_file); unlink(text_file_name); }
    if (union_file) { fclose(union_file); unlink(union_file_name); }
    exit(k);
}
Example #10
0
/**
 * @brief Check if given credentials are correct
 * @param user - struct containing username and password for check
 * @return 1 if credentials are valid 0 otherwise
 *
 * Function opens a file with all users and passwords and then it is trying to find given user in the file with all registered users.
 * If we find a user we check if the password is the same as password given at registration if yes returns 1 else 0.
 */
int user_auth(user_t * user){

    //file contains all registered logins and passwords
    FILE * login = fopen("login","r");

    //if file doesn't exist - there are no valid logins and password - credentials are wrong
    if(!login)
        return 0;

    //find given username and password in login file
    char username[BUFFER_SIZE],password[BUFFER_SIZE];
    while(fgets(username,BUFFER_SIZE,login)!=NULL){
        fgets(password,BUFFER_SIZE,login);
        username[strlen(username)-1]='\0';
        password[strlen(password)-1]='\0';
        
        //if we found suitable username and password credentials are OK
        if(!strcmp(user->username,username) && !strcmp(user->password,password)){
            fclose(login);
           return 1;
        }
    }
    fclose(login);
    //we didn't find given login and password
    return 0;
}
int read_prop(MNL_CONFIG_T* prConfig, const char* name)
{
    FILE *fp = fopen(name, "rb");
	char *key, *val;
    if (!fp){
        MNL_MSG("%s: open %s fail!\n",__FUNCTION__,name);
        return -1;
    }
    while(fgets(propbuf, sizeof(propbuf), fp))
    {
        if (get_prop(propbuf, &key, &val))
        {
			MNL_MSG("%s: Get Property fails!!\n", __FUNCTION__);
            fclose(fp);
			return -1;
		}
		if (!key || !val)
			continue;
		//MNL_MSG("%s: Get Property: '%s' => '%s'\n", __FUNCTION__, key, val);
		if (set_prop(prConfig, key,val))
        {
			MNL_ERR("%s: Set Property fails!!\n", __FUNCTION__);
            fclose(fp);
			return -1;
		}
    }
    fclose(fp);
    return 0;
}
Example #12
0
int filecopy( char *fname, char *sname )
{
    FILE *fp;
    FILE *fp2;
    int flen, rval;
    int max=0x8000;
    char *mem;
    rval=1;
    mem=mem_ini(max);
    fp=fopen(fname,"rb");
    if (fp==NULL) goto jobov;
    fp2=fopen(sname,"wb");
    if (fp2==NULL) goto jobov;
    while(1) {
        flen = (int)fread( mem, 1, max, fp );
        if (flen==0) break;
        fwrite( mem, 1, flen, fp2 );
        if (flen<max) break;
    }
    fclose(fp2);
    fclose(fp);
    rval=0;
jobov:
    mem_bye(mem);
    return rval;
}
Example #13
0
bool Map::Load(std::string filename) {
	FILE *f = fopen(filename.c_str(), "rb");
	if(f) {
		uint32 version;
		if(fread(&version, sizeof(version), 1, f) != 1) {
			fclose(f);
			return false;
		}
		
		if(version == 0x01000000) {
			bool v = LoadV1(f);
			fclose(f);
			return v;
		} else if(version == 0x02000000) {
			bool v = LoadV2(f);
			fclose(f);
			return v;
		} else {
			fclose(f);
			return false;
		}
	}
	
	return false;
}
Example #14
0
bool CVSService::setUserPassword(const char *username, const char *password)
{
	// Repository is not initialized, just return false.
	if (!m_isRepoInitialized)
		return false;

	char filename[MAX_PATH + 24];
	FILE *fp;

	// Write user name password to 'passwd' file.
	if ((fp = fopen(strcat(strcpy(filename, m_repoPath), "/CVSROOT/passwd"), "w")) == NULL)
		return false;
	fprintf(fp, "%s:%s:%s\n", username, __crypt(password), getpwuid(getuid())->pw_name);
	fclose(fp);

	// Write user name to 'reader' file.
	if ((fp = fopen(strcat(strcpy(filename, m_repoPath), "/CVSROOT/reader"), "w")) == NULL)
		return false;
	fprintf(fp, "%s\n", username);
	fclose(fp);

	// Write user name to 'writer' file.
	if ((fp = fopen(strcat(strcpy(filename, m_repoPath), "/CVSROOT/writer"), "w")) == NULL)
		return false;
	fprintf(fp, "%s\n", username);
	fclose(fp);

	// Return true.
	return true;
}
Example #15
0
File: bat.c Project: gabeg805/Atlas
// Return the battery charge level
static int get_charge() {
    
    // Initialize file handler
    FILE *handle;
    
    // Get contents of NOW file
    handle = fopen(CHARGE_NOW_FILE, "r");
    char charge_now[10];
    fgets(charge_now, sizeof(charge_now), handle);    
    fclose(handle);
    
    // Get contents of FULL file
    handle = fopen(CHARGE_FULL_FILE, "r");
    char charge_full[10];
    fgets(charge_full, sizeof(charge_full), handle);    
    fclose(handle);
    
    // Get contents of STATUS file
    handle = fopen(CHARGE_STATUS_FILE, "r");
    char charge_status[10];
    fgets(charge_status, sizeof(charge_status), handle);    
    fclose(handle);
    
    // Calculate charge
    int charge;
    if ( strcmp(charge_status, "Charging\n") == 0 ) 
        charge = -1;
    else {
        int now = atoi(charge_now);
        int full = atoi(charge_full);
        charge = 100.0f * now / full;
    }
    
    return charge;
}    
Example #16
0
// 暗号化されたファイルを読み込んで、_Output内に格納
bool CKakusi::ModosiFile( char* _Filename, unsigned char* _Output )
{
	FILE* _fp;
	unsigned char *pBuffer = NULL;
	bool ret;

	try {
		if (fopen_s(&_fp, _Filename, "rb")) return false;

		// file size
		long size = 0;
		fseek( _fp, 0, SEEK_END );
		size = ftell( _fp );
		fseek( _fp, 0, SEEK_SET );
		if ( size <= 0 ) {
			fclose( _fp );
			return false;
		}		

		pBuffer = new unsigned char[size];

		fread(pBuffer, size, 1, _fp);

		kakusibako.Decrypt(pBuffer, _Output, size);

		ret = true;
	} catch(...) {
		ret = false;
	}

	if (_fp) fclose( _fp );
	delete [] pBuffer;
	return ret;
}
Example #17
0
int rename(const char *oldpath, const char *newpath)
{
    if (!monapi_file_exists(oldpath)) {
        return -1;
    }
    char buf[RENAME_BUF_SIZE];
    FILE* src = fopen(oldpath, "r");
    if (src == NULL) {
        return -1;
    }
    FILE* dest = fopen(newpath, "w");
    if (dest == NULL) {
        fclose(src);
        return -1;
    }
    size_t size;
    while (size = fread(buf, 1, RENAME_BUF_SIZE, src)) {
        if (fwrite(buf, 1, size, dest) != size) {
            fclose(dest);
            fclose(src);
            return -1;
        }
    }
    fclose(dest);
    fclose(src);
    if (unlink(oldpath) != 0) {
        return -1;
    }
    return 0;
}
Example #18
0
// SPICE to Qucs conversion.
int spice2qucs (struct actionset_t * action, char * infile, char * outfile) {
  int ret = 0;
  if ((spice_in = open_file (infile, "r")) == NULL) {
    ret = -1;
  } else if (spice_parse () != 0) {
    ret = -1;
  } else if (spice_checker () != 0) {
    ret = -1;
  }
  spice_lex_destroy ();
  if (spice_in)
    fclose (spice_in);
  if (ret) {
    spice_destroy ();
    return -1;
  }

  if ((qucs_out = open_file (outfile, "w")) == NULL)
    return -1;
  if (!strcmp (action->out, "qucs"))
    qucs_producer ();
  else /* "qucslib" */
    qucslib_producer ();
  fclose (qucs_out);
  spice_destroy ();
  return 0;
}
Example #19
0
int read_image(dt_imageio_module_data_t *jpg_tmp, uint8_t *out)
{
  dt_imageio_jpeg_t *jpg = (dt_imageio_jpeg_t *)jpg_tmp;
  struct dt_imageio_jpeg_error_mgr jerr;
  jpg->dinfo.err = jpeg_std_error(&jerr.pub);
  if(setjmp(jerr.setjmp_buffer))
  {
    jpeg_destroy_decompress(&(jpg->dinfo));
    fclose(jpg->f);
    return 1;
  }
  (void)jpeg_start_decompress(&(jpg->dinfo));
  JSAMPROW row_pointer[1];
  row_pointer[0] = (uint8_t *)malloc((size_t)jpg->dinfo.output_width * jpg->dinfo.num_components);
  uint8_t *tmp = out;
  while(jpg->dinfo.output_scanline < jpg->dinfo.image_height)
  {
    if(jpeg_read_scanlines(&(jpg->dinfo), row_pointer, 1) != 1) return 1;
    if(jpg->dinfo.num_components < 3)
      for(JDIMENSION i = 0; i < jpg->dinfo.image_width; i++)
        for(int k = 0; k < 3; k++) tmp[4 * i + k] = row_pointer[0][jpg->dinfo.num_components * i + 0];
    else
      for(JDIMENSION i = 0; i < jpg->dinfo.image_width; i++)
        for(int k = 0; k < 3; k++) tmp[4 * i + k] = row_pointer[0][3 * i + k];
    tmp += 4 * jpg->width;
  }
  // (void)jpeg_finish_decompress(&(jpg->dinfo));
  jpeg_destroy_decompress(&(jpg->dinfo));
  free(row_pointer[0]);
  fclose(jpg->f);
  return 0;
}
Example #20
0
// VCD to Qucs conversion.
int vcd2qucs (struct actionset_t * action, char * infile, char * outfile) {
  int ret = 0;
  vcd_init ();
  if ((vcd_in = open_file (infile, "r")) == NULL) {
    ret = -1;
  } else if (vcd_parse () != 0) {
    ret = -1;
  } else if (vcd_checker () != 0) {
    ret = -1;
  }
  vcd_lex_destroy ();
  if (vcd_in)
    fclose (vcd_in);
  if (ret) {
    vcd_destroy ();
    return -1;
  }

  if ((qucs_out = open_file (outfile, "w")) == NULL)
    return -1;
  if (!strcmp (action->out, "qucsdata"))
    qucsdata_producer_vcd ();
  fclose (qucs_out);
  vcd_destroy ();
  return 0;
}
static char* log_reader_fails_with_incorrect_version()
{
    const char* log_with_invalid_version =
    "#[Test log]\n"
    "#[Histogram log format version 1.04]\n"
    "#[StartTime: 1404700005.222 (seconds since epoch), Mon Jul 02:26:45 GMT 2014]\n"
    "StartTimestamp\",\"EndTimestamp\",\"Interval_Max\",\"Interval_Compressed_Histogram\"\n";
    const char* file_name = "histogram_with_invalid_version.log";
    struct hdr_log_reader reader;
    FILE* log_file;

    log_file = fopen(file_name, "w+");
    fprintf(log_file, "%s", log_with_invalid_version);
    fflush(log_file);
    fclose(log_file);

    log_file = fopen(file_name, "r");
    hdr_log_reader_init(&reader);
    int r = hdr_log_read_header(&reader, log_file);

    mu_assert("Should error with incorrect version", r == HDR_LOG_INVALID_VERSION);

    fclose(log_file);
    remove(file_name);

    return 0;
}
Example #22
0
// Qucs dataset to CSV conversion.
int qucs2csv (struct actionset_t * action, char * infile, char * outfile) {
  int ret = 0;
  if ((dataset_in = open_file (infile, "r")) == NULL) {
    ret = -1;
  } else if (dataset_parse () != 0) {
    ret = -1;
  } else if (dataset_result == NULL) {
    ret = -1;
  } else if (dataset_check (dataset_result) != 0) {
    delete dataset_result;
    dataset_result = NULL;
    ret = -1;
  }
  qucs_data = dataset_result;
  dataset_result = NULL;
  dataset_lex_destroy ();
  if (dataset_in)
    fclose (dataset_in);
  if (ret)
    return -1;

  if ((csv_out = open_file (outfile, "w")) == NULL)
    return -1;
  if (!strcmp (action->out, "csv")) {
    if (data_var != NULL)
      csv_producer (data_var, ";");
    else {
      fprintf (stderr, "no data variable given (passed by -d option)\n");
      ret = -1;
    }
    fclose (csv_out);
    return ret;
  }
  return -1;
}
Example #23
0
/**
 * Main function
 * \brief Main function
 * \param argc  A count of the number of command-line arguments
 * \param argv  An argument vector of the command-line arguments.
 * \warning Must be called with two filenames patchFile, originalFile as commandline parameters and in the given order.
 * \returns { 0 if succeeds, exit code otherwise}
 */
int main (int argc, char *argv[]) {
    FILE *patchFile;
    FILE *originalFile;

    if(argc<3) {
        fprintf(stderr, "!!!!! Usage: ./applyPatch patchFile originalFile !!!!!\n");
        exit(EXIT_FAILURE); /* indicate failure.*/
    }

    patchFile = fopen(argv[1] , "r" );
    originalFile = fopen(argv[2] , "r" );

    if (patchFile==NULL) {
        fprintf(stderr, "!!!!! Error opening patchFile !!!!! \n");
        exit(EXIT_FAILURE);
    }
    if (originalFile==NULL) {
        fprintf (stderr, "!!!!! Error opening originalFile !!!!!\n");
        exit(EXIT_FAILURE);
    }

    applyPatch(patchFile, originalFile);

    fclose(patchFile);
    fclose(originalFile);
    return 0;
}
Example #24
0
// Qucs dataset to Matlab conversion.
int qucs2mat (struct actionset_t * action, char * infile, char * outfile) {
  int ret = 0;
  if ((dataset_in = open_file (infile, "r")) == NULL) {
    ret = -1;
  } else if (dataset_parse () != 0) {
    ret = -1;
  } else if (dataset_result == NULL) {
    ret = -1;
  } else if (dataset_check (dataset_result) != 0) {
    delete dataset_result;
    dataset_result = NULL;
    ret = -1;
  }
  qucs_data = dataset_result;
  dataset_result = NULL;
  dataset_lex_destroy ();
  if (dataset_in)
    fclose (dataset_in);
  if (ret)
    return -1;

  if ((matlab_out = open_file (outfile, "wb")) == NULL)
    return -1;
  if (!strcmp (action->out, "matlab")) {
    matlab_producer ();
    fclose (matlab_out);
    return ret;
  }
  return -1;
}
Example #25
0
int main(int argc, char *argv[])
{
	char file[100];
	char target[100];
	char line[1000];
	FILE *fp1, *fp2;

	strcpy(file, argv[1]);
	strcpy(target, argv[2]);

	fp1 = fopen(file, "r");
	fp2 = fopen(target, "w");
	if (!fp1 || !fp2)
	{
		printf("Fail to open the file!\n");
		exit(-1);
	}
	
	while (fgets(line, 1000, fp1))
	{
		if (line[0] != '#')
			fputs(line, fp2);
	}

	fclose(fp1);
	fclose(fp2);

	return 0;
}
Example #26
0
// =========================static functions===================================
int Precanned::parseSudokuFile(const char * fileName, int * data) {
    FILE * fd = fopen(fileName, "r");
    if (NULL == fd) {
        return Precanned::ERR_FILE_NOTOPEN;
    }

    int row = 0;
    char line[32] = {'\0'};

    while(fgets(line, sizeof(line), fd)) {
        if ( strlen( line ) == 0 )
            break;

        if (row > 9)
            break;

        if ( !parseLine(line, row, data) ) {
            fclose(fd);
            return Precanned::ERR_BAD_LINE;
        }

        row++;
        memset(line, 0x00, sizeof(line));
    }

    fclose(fd);

    if ( row == 0 )
        return Precanned::ERR_FILE_EMPTY;
    else if ( row != 9 )
        return Precanned::ERR_BAD_ROW;
    else
        return Precanned::ERR_NO_ERROR;
}
Example #27
0
/* system dependent call to get IEEE node ID.
   This sample implementation generates a random node ID. */
void get_ieee_node_identifier(uuid_node_t *node)
{
    static inited = 0;
    static uuid_node_t saved_node;
    char seed[16];
    FILE *fp;

    if (!inited) {
        fp = fopen("nodeid", "rb");
        if (fp) {
            fread(&saved_node, sizeof(saved_node), 1, fp);
            fclose(fp);
        } else {
            get_random_info(seed);
            seed[0] |= 0x01;
            memcpy(&saved_node, seed, sizeof(saved_node));
            fp = fopen("nodeid", "wb");
            if (fp) {
                fwrite(&saved_node, sizeof(saved_node), 1, fp);
                fclose(fp);
            }
        }
        inited = 1;
    }

    *node = saved_node;
}
Example #28
0
int main(int argc, char **argv)
{
    char str[1024];
    char *pre = "<a href=\"http://";
    char *mid = "\" target=\"_blank\">";
    char *end = "</a>";
    FILE *in, *out;

    in = fopen(argv[1], "r");
    out = fopen(argv[2], "w");

    if (!in || !out) {
        perror("Open failed");
        return -1;
    }

    while (fscanf(in, "%s", str)) {
        fprintf(out, "%s%s%s%s%s\n", pre, str, mid, str, end);
    }

    fclose(in);
    fclose(out);

    return 0;
}
char *
vncDecryptPasswdFromFile(char *fname)
{
    FILE *fp;
    int i, ch;
    unsigned char *passwd = (unsigned char *)malloc(9);

    if ((fp = fopen(fname,"r")) == NULL) return NULL;

    for (i = 0; i < 8; i++) {
        ch = getc(fp);
        if (ch == EOF) {
            fclose(fp);
            return NULL;
        }
        passwd[i] = ch;
    }

    fclose(fp);

    deskey(fixedkey, DE1);
    des(passwd, passwd);

    passwd[8] = 0;

    return (char *)passwd;
}
Example #30
0
int main(int argc, char* argv[]) {
	
	errno_t err;
    char str[50]; 
    FILE *file1;
    FILE *file2;
	char ch1[] = "C:\\c++\\epbgit\\ConsoleApplication\\Debug\\out\\a.txt";
	char ch2[] = "C:\\c++\\epbgit\\ConsoleApplication\\Debug\\out\\b.txt";
	                        
	
    if(err = fopen_s(&file1,ch1, "r")) { 
        puts("來源檔案開啟失敗"); 
        return 1; 
    }
    
    if(err = fopen_s(&file2,ch2, "w")) { 
        puts("目的檔案開啟失敗"); 
        return 1; 
    }    
                                    
    while((fgets(str,50,file1)) != NULL) { 
        fputs(str, file2);
    } 
          
    fclose(file1);
    fclose(file2);
        
	system("pause");
    return 0; 
}