zdiff.cc (zutils-1.9.tar.lz) | : | zdiff.cc (zutils-1.10.tar.lz) | ||
---|---|---|---|---|
/* Zdiff - decompress and compare two files line by line | /* Zdiff - decompress and compare two files line by line | |||
Copyright (C) 2010-2020 Antonio Diaz Diaz. | Copyright (C) 2010-2021 Antonio Diaz Diaz. | |||
This program is free software: you can redistribute it and/or modify | This program is free software: you can redistribute it and/or modify | |||
it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | |||
the Free Software Foundation, either version 2 of the License, or | the Free Software Foundation, either version 2 of the License, or | |||
(at your option) any later version. | (at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | GNU General Public License for more details. | |||
skipping to change at line 116 | skipping to change at line 116 | |||
extern "C" void remove_fifos() | extern "C" void remove_fifos() | |||
{ | { | |||
if( fifonames[0].size() ) | if( fifonames[0].size() ) | |||
{ std::remove( fifonames[0].c_str() ); fifonames[0].clear(); } | { std::remove( fifonames[0].c_str() ); fifonames[0].clear(); } | |||
if( fifonames[1].size() ) | if( fifonames[1].size() ) | |||
{ std::remove( fifonames[1].c_str() ); fifonames[1].clear(); } | { std::remove( fifonames[1].c_str() ); fifonames[1].clear(); } | |||
} | } | |||
/* Set fifonames[i] to "${TMPDIR}/<coded_pid>[_-]<basename(filenames[i])>" | /* Set fifonames[i] to "${TMPDIR}/<coded_pid>[_-]<basename(filenames[i])>" | |||
and create FIFOs. */ | and create FIFOs. The pid is coded in little endian order. | |||
*/ | ||||
bool set_fifonames( const std::string filenames[2] ) | bool set_fifonames( const std::string filenames[2] ) | |||
{ | { | |||
enum { num_codes = 36 }; | enum { num_codes = 36 }; | |||
const char * const codes = "0123456789abcdefghijklmnopqrstuvwxyz"; | const char * const codes = "0123456789abcdefghijklmnopqrstuvwxyz"; | |||
const char * p = std::getenv( "TMPDIR" ); | const char * p = std::getenv( "TMPDIR" ); | |||
if( p ) { fifonames[0] = p; fifonames[0] += '/'; } | if( p ) { fifonames[0] = p; fifonames[0] += '/'; } | |||
else fifonames[0] = "/tmp/"; | else fifonames[0] = "/tmp/"; | |||
int n = getpid(); | int n = getpid(); | |||
unsigned pos = fifonames[0].size(); | do fifonames[0] += codes[n % num_codes]; while( n /= num_codes ); | |||
do fifonames[0].insert( pos, 1, codes[n % num_codes] ); | const unsigned pos = fifonames[0].size(); | |||
while( n /= num_codes ); | fifonames[0] += '_'; | |||
pos = fifonames[0].size(); | ||||
fifonames[1] = fifonames[0]; | fifonames[1] = fifonames[0]; | |||
fifonames[0] += '_'; fifonames[0] += my_basename( filenames[0].c_str() ); | fifonames[0] += my_basename( filenames[0].c_str() ); | |||
fifonames[1] += '_'; fifonames[1] += my_basename( filenames[1].c_str() ); | fifonames[1] += my_basename( filenames[1].c_str() ); | |||
if( fifonames[1] == fifonames[0] ) fifonames[1][pos] = '-'; | if( fifonames[1] == fifonames[0] ) fifonames[1][pos] = '-'; | |||
for( int i = 0; i < 2; ++i ) | for( int i = 0; i < 2; ++i ) | |||
if( mkfifo( fifonames[i].c_str(), S_IRUSR | S_IWUSR ) != 0 ) | if( mkfifo( fifonames[i].c_str(), S_IRUSR | S_IWUSR ) != 0 ) | |||
{ | { | |||
if( errno == EEXIST ) | if( errno == EEXIST ) | |||
{ | { | |||
std::remove( fifonames[i].c_str() ); | std::remove( fifonames[i].c_str() ); | |||
if( mkfifo( fifonames[i].c_str(), S_IRUSR | S_IWUSR ) == 0 ) | if( mkfifo( fifonames[i].c_str(), S_IRUSR | S_IWUSR ) == 0 ) | |||
continue; | continue; | |||
End of changes. 4 change blocks. | ||||
8 lines changed or deleted | 8 lines changed or added |