OK, this is what/how I did it, which caomplied without errors or wanings
using the compiler flags: "-ansi -pedantic -Wall"
..
and BTW I am obviously working with some plain files (off a file system)
..
/* x platform (standard ANCI C) */
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
char *getYYYYmmDDHHMMSS(char*, time_t);
int main(int argc, char **argv){
time_t start_t;
int iR;
char *aLogFl;
FILE *LOGFL = NULL;
struct tm *timeinfo;
iR = EXIT_FAILURE;
if((argv != NULL) && (argv[0] != NULL) && (strlen(argv[0]) > 0)){
iR = EXIT_SUCCESS;
time(&start_t);
aLogFl = getYYYYmmDDHHMMSS(argv[0], start_t);
if((LOGFL = fopen(aLogFl, "w+t")) == NULL){
fprintf(stderr, "\n Cannot open log file: %s\n", aLogFl);
goto end;
}
timeinfo = localtime (&start_t);
fprintf(LOGFL, "// __ run date and time are: %s", asctime (timeinfo));
fprintf(LOGFL, "// __ log file is: %s\n", aLogFl);
}
if(LOGFL != NULL){ fclose(LOGFL); }
end:;
exit(iR);
}
char *getYYYYmmDDHHMMSS(char *KdNm, time_t start_t){
int i, iSL = strlen(KdNm), ISS = 0, iBuf, iSz;
char *aKdNm02 = NULL;
char *aLogFl = NULL;
/* gcc [.|./] "/usr/bin/ld: [*]: No such file: File format not recognized"
*/
if(strncmp("./", KdNm, 2) == 0){ ISS = 2; }
else if(strncmp(".", KdNm, 1) == 0){ ISS = 1; }
iBuf = (iSL - ISS) + 1;
aKdNm02 = (char *)malloc(iBuf);
for(i = 0; (i < (iSL - ISS)); ++i){ aKdNm02 = KdNm[i + ISS]; }
iSz = strlen("YYYYMMDDHHMMSS_") + strlen(aKdNm02) + strlen(".log") + 1;
aLogFl = (char*)malloc(iSz);
strftime(aLogFl, sizeof("YYYYmmDDHHMMSS"), "%Y%m%d%H%M%S",
localtime(&start_t));
strcat(aLogFl, "_"); strcat(aLogFl, aKdNm02); strcat(aLogFl, ".log");
return(aLogFl);
}