No empty .Rs/.Re
[netbsd-mini2440.git] / usr.sbin / isdn / isdntrace / trace.c
blob92a3718fe9d62c38bf1e77c3dc73dbfdd64e44a5
1 /*
2 * Copyright (c) 1996, 2000 Hellmuth Michaelis. All rights reserved.
4 * Copyright (c) 1996 Gary Jennejohn. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the author nor the names of any co-contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 * 4. Altered versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software and/or documentation.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
33 *---------------------------------------------------------------------------*
35 * trace.c - print traces of D (B) channel activity for isdn4bsd
36 * -------------------------------------------------------------
38 * $Id: trace.c,v 1.10 2009/04/16 05:56:33 lukem Exp $
40 * $FreeBSD$
42 * last edit-date: [Sat Jan 6 13:06:03 2001]
44 *---------------------------------------------------------------------------*/
46 #include "trace.h"
48 unsigned char buf[BSIZE];
49 FILE *Fout = NULL;
50 FILE *BP = NULL;
51 int outflag = 1;
52 int header = 1;
53 int print_q921 = 1;
54 int unit = 0;
55 int dchan = 0;
56 int bchan = 0;
57 int traceon = 0;
58 int analyze = 0;
59 int Rx = RxUDEF;
60 int Tx = TxUDEF;
61 int f;
62 int Bopt = 0;
63 int Popt = 0;
64 int bpopt = 0;
65 int info = 0;
66 int Fopt = 0;
67 int xopt = 1;
69 int enable_trace = TRACE_D_RX | TRACE_D_TX;
71 static char outfilename[MAXPATHLEN];
72 static char routfilename[MAXPATHLEN];
73 static char BPfilename[MAXPATHLEN];
74 static char rBPfilename[MAXPATHLEN];
76 static struct stat fst;
78 static void dumpbuf( int n, unsigned char *buf, struct i4b_trace_hdr *hdr, int raw );
79 static int switch_driver( int value, int rx, int tx );
80 static void usage( void );
81 static void exit_hdl( void );
82 static void reopenfiles( int );
83 void add_datetime(char *filename, char *rfilename);
84 char * fmt_hdr(struct i4b_trace_hdr *hdr, int frm_len);
86 /*---------------------------------------------------------------------------*
87 * usage instructions
88 *---------------------------------------------------------------------------*/
89 void
90 usage(void)
92 fprintf(stderr,"\n");
93 fprintf(stderr,"isdntrace - i4b package ISDN trace facility for passive cards (%02d.%02d.%d)\n", VERSION, REL, STEP);
94 fprintf(stderr,"usage: isdntrace -a -b -d -f <file> -h -i -l -n <val> -o -p <file> -r -u <unit>\n");
95 fprintf(stderr," -x -B -F -P -R <unit> -T <unit>\n");
96 fprintf(stderr," -a analyzer mode ................................... (default off)\n");
97 fprintf(stderr," -b switch B channel trace on ....................... (default off)\n");
98 fprintf(stderr," -d switch D channel trace off ....................... (default on)\n");
99 fprintf(stderr," -f <file> write output to file filename ............ (default %s0)\n", TRACE_FILE_NAME);
100 fprintf(stderr," -h don't print header for each message ............. (default off)\n");
101 fprintf(stderr," -i print I.430 (layer 1) INFO signals .............. (default off)\n");
102 fprintf(stderr," -l don't decode low layer Q.921 messages ........... (default off)\n");
103 fprintf(stderr," -n <val> process packet if it is longer than <val> octetts . (default 0)\n");
104 fprintf(stderr," -o don't write output to a file .................... (default off)\n");
105 fprintf(stderr," -p <file> specify filename for -B and -P ........ (default %s0)\n", BIN_FILE_NAME);
106 fprintf(stderr," -r don't print raw hex/ASCII dump of protocol ...... (default off)\n");
107 fprintf(stderr," -u <unit> specify controller unit number ............... (default unit 0)\n");
108 fprintf(stderr," -x show packets with unknown protocol discriminator (default off)\n");
109 fprintf(stderr," -B write binary trace data to file filename ........ (default off)\n");
110 fprintf(stderr," -F with -P and -p: wait for more data at EOF ....... (default off)\n");
111 fprintf(stderr," -P playback from binary trace data file ............ (default off)\n");
112 fprintf(stderr," -R <unit> analyze Rx controller unit number (for -a) ... (default unit %d)\n", RxUDEF);
113 fprintf(stderr," -T <unit> analyze Tx controller unit number (for -a) ... (default unit %d)\n", TxUDEF);
114 fprintf(stderr,"\n");
115 exit(1);
118 /*---------------------------------------------------------------------------*
119 * main
120 *---------------------------------------------------------------------------*/
122 main(int argc, char *argv[])
124 extern int optind;
125 extern int opterr;
126 extern char *optarg;
127 char devicename[80];
128 char headerbuf[256];
130 int n;
131 int c;
132 char *b;
134 const char *outfile = TRACE_FILE_NAME;
135 const char *binfile = BIN_FILE_NAME;
136 int outfileset = 0;
137 int raw = 1;
138 int noct = -1;
139 time_t tm;
140 struct i4b_trace_hdr *ithp = NULL;
141 int l;
142 static struct stat fstnew;
144 b = &buf[sizeof(struct i4b_trace_hdr)];
146 while( (c = getopt(argc, argv, "abdf:hiln:op:ru:xBFPR:T:")) != -1)
148 switch (c)
150 case 'a':
151 analyze = 1;
152 break;
154 case 'b':
155 enable_trace |= (TRACE_B_RX | TRACE_B_TX);
156 break;
158 case 'd':
159 enable_trace &= (~(TRACE_D_TX | TRACE_D_RX));
160 break;
162 case 'o':
163 outflag = 0;
164 break;
166 case 'f':
167 outfile = optarg;
168 outfileset = 1;
169 break;
171 case 'n':
172 noct = atoi(optarg);
173 break;
175 case 'h':
176 header = 0;
177 break;
179 case 'i':
180 enable_trace |= TRACE_I;
181 info = 1;
182 break;
184 case 'l':
185 print_q921 = 0;
186 break;
188 case 'p':
189 binfile = optarg;
190 bpopt = 1;
191 break;
193 case 'r':
194 raw = 0;
195 break;
197 case 'u':
198 unit = atoi(optarg);
199 break;
201 case 'x':
202 xopt = 0;
203 break;
205 case 'B':
206 Bopt = 1;
207 break;
209 case 'F':
210 Fopt = 1;
211 break;
213 case 'P':
214 Popt = 1;
215 break;
217 case 'R':
218 Rx = atoi(optarg);
219 break;
221 case 'T':
222 Tx = atoi(optarg);
223 break;
225 case '?':
226 default:
227 usage();
228 break;
232 if (enable_trace == 0)
233 usage();
235 if (Bopt && Popt)
236 usage();
238 atexit(exit_hdl);
240 if (Bopt)
242 if (bpopt)
243 snprintf(BPfilename, sizeof(BPfilename), "%s", binfile);
244 else
245 snprintf(BPfilename, sizeof(BPfilename), "%s%d",
246 BIN_FILE_NAME, unit);
248 add_datetime(BPfilename, rBPfilename);
250 if ((BP = fopen(rBPfilename, "w")) == NULL)
252 char buffer[80];
254 snprintf(buffer, sizeof(buffer),
255 "Error opening file [%s]", rBPfilename);
256 perror(buffer);
257 exit(1);
260 if ((setvbuf(BP, (char *)NULL, _IONBF, 0)) != 0)
262 char buffer[80];
264 snprintf(buffer, sizeof(buffer),
265 "Error setting file [%s] to unbuffered",
266 rBPfilename);
267 perror(buffer);
268 exit(1);
272 if (Popt)
274 if (bpopt)
275 snprintf(BPfilename, sizeof(BPfilename), "%s", binfile);
276 else
277 snprintf(BPfilename, sizeof(BPfilename), "%s%d",
278 BIN_FILE_NAME, unit);
280 strlcpy(rBPfilename, BPfilename, sizeof(rBPfilename));
282 if ((BP = fopen(BPfilename, "r")) == NULL)
284 char buffer[80];
286 snprintf(buffer, sizeof(buffer),
287 "Error opening file [%s]", BPfilename);
288 perror(buffer);
289 exit(1);
291 if (Fopt)
293 if (fstat(fileno(BP), &fst))
295 char buffer[80];
296 snprintf(buffer, sizeof(buffer),
297 "Error fstat file [%s]", BPfilename);
298 perror(buffer);
299 exit(1);
303 else
305 snprintf(devicename, sizeof(devicename), "%s%d",
306 I4BTRC_DEVICE, unit);
308 if ((f = open(devicename, O_RDWR)) < 0)
310 char buffer[80];
312 snprintf(buffer, sizeof(buffer),
313 "Error opening trace device [%s]", devicename);
314 perror(buffer);
315 exit(1);
319 if (outflag)
321 if (outfileset == 0)
322 snprintf(outfilename, sizeof(outfilename), "%s%d",
323 TRACE_FILE_NAME, unit);
324 else
325 strlcpy(outfilename, outfile, sizeof(outfilename));
327 add_datetime(outfilename, routfilename);
329 if ((Fout = fopen(routfilename, "w")) == NULL)
331 char buffer[80];
333 snprintf(buffer, sizeof(buffer),
334 "Error opening file [%s]", routfilename);
335 perror(buffer);
336 exit(1);
339 if ((setvbuf(Fout, (char *)NULL, _IONBF, 0)) != 0)
341 char buffer[80];
343 snprintf(buffer, sizeof(buffer),
344 "Error setting file [%s] to unbuffered",
345 routfilename);
346 perror(buffer);
347 exit(1);
351 if ((setvbuf(stdout, (char *)NULL, _IOLBF, 0)) != 0)
353 char buffer[80];
355 snprintf(buffer, sizeof(buffer),
356 "Error setting stdout to line-buffered");
357 perror(buffer);
358 exit(1);
361 if (!Popt)
363 if ((switch_driver(enable_trace, Rx, Tx)) == -1)
364 exit(1);
365 else
366 traceon = 1;
369 signal(SIGHUP, SIG_IGN); /* ignore hangup signal */
370 signal(SIGUSR1, reopenfiles); /* rotate logfile(s) */
372 time(&tm);
374 if (analyze)
376 snprintf(headerbuf, sizeof(headerbuf),
377 "\n==== isdnanalyze controller rx #%d - tx #%d ==== started %s",
378 Rx, Tx, ctime(&tm));
380 else
382 snprintf(headerbuf, sizeof(headerbuf),
383 "\n=========== isdntrace controller #%d =========== started %s",
384 unit, ctime(&tm));
387 printf("%s", headerbuf);
389 if (outflag)
390 fprintf(Fout, "%s", headerbuf);
392 for (;;)
394 if (Popt == 0)
396 char buffer[80];
397 n = read(f, buf, BSIZE);
398 if (n == -1)
400 snprintf(buffer, sizeof(buffer),
401 "Error reading trace device");
402 perror(buffer);
403 exit(1);
406 if (Bopt)
408 if ((int)(fwrite(buf, 1, n, BP)) != n)
410 snprintf(buffer, sizeof(buffer),
411 "Error writing file [%s]",
412 rBPfilename);
413 perror(buffer);
414 exit(1);
418 n -= sizeof(struct i4b_trace_hdr);
420 else
422 again:
423 if ((fread(buf, 1, sizeof(struct i4b_trace_hdr), BP)) != sizeof(struct i4b_trace_hdr))
425 if (feof(BP))
427 if (Fopt)
429 if (ferror(BP))
431 char buffer[80];
432 snprintf(buffer, sizeof(buffer), "Error reading hdr from file [%s]", rBPfilename);
433 perror(buffer);
434 exit(1);
437 usleep(250000);
438 clearerr(BP);
440 if (stat(rBPfilename, &fstnew) != -1)
442 if ((fst.st_ino != fstnew.st_ino) ||
443 (fstnew.st_nlink == 0))
445 if ((BP = freopen(rBPfilename, "r", BP)) == NULL)
447 char buffer[80];
448 snprintf(buffer, sizeof(buffer), "Error reopening file [%s]", rBPfilename);
449 perror(buffer);
450 exit(1);
452 stat(rBPfilename, &fst);
455 goto again;
457 else
459 printf("\nEnd of playback input file reached.\n");
460 exit(0);
463 else
465 char buffer[80];
466 snprintf(buffer, sizeof(buffer),
467 "Error reading hdr from file [%s]",
468 rBPfilename);
469 perror(buffer);
470 exit(1);
474 ithp = (struct i4b_trace_hdr *)buf;
475 l = ithp->length - sizeof(struct i4b_trace_hdr);
477 if ((n = fread(buf+sizeof(struct i4b_trace_hdr), 1, l , BP)) != l)
479 char buffer[80];
480 snprintf(buffer, sizeof(buffer),
481 "Error reading data from file [%s]",
482 rBPfilename);
483 perror(buffer);
484 exit(1);
489 if ((n > 0) && (n > noct))
491 dumpbuf(n, b, (struct i4b_trace_hdr *)buf, raw);
496 /*---------------------------------------------------------------------------*
497 * format header into static buffer, return buffer address
498 *---------------------------------------------------------------------------*/
499 char *
500 fmt_hdr(struct i4b_trace_hdr *hdr, int frm_len)
502 struct tm *s;
503 static char hbuf[256];
504 int i = 0;
505 time_t secs = hdr->time.tv_sec;
507 s = localtime(&secs);
509 if (hdr->type == TRC_CH_I) /* Layer 1 INFO's */
511 snprintf(hbuf, sizeof(hbuf),
512 "\n-- %s - isdnif:%d ------------- time:%2.2d.%2.2d %2.2d:%2.2d:%2.2d.%06u ",
513 ((hdr->dir) ? "NT->TE" : "TE->NT"), hdr->isdnif,
514 s->tm_mday, s->tm_mon + 1, s->tm_hour, s->tm_min,
515 s->tm_sec, (u_int32_t)hdr->time.tv_usec);
517 else
519 if (hdr->trunc > 0)
521 snprintf(hbuf, sizeof(hbuf),
522 "\n-- %s - isdnif:%d - frame:%6.6u - time:%2.2d.%2.2d %2.2d:%2.2d:%2.2d.%06u - length:%d (%d) ",
523 ((hdr->dir) ? "NT->TE" : "TE->NT"), hdr->isdnif,
524 hdr->count, s->tm_mday, s->tm_mon + 1, s->tm_hour,
525 s->tm_min, s->tm_sec, (u_int32_t)hdr->time.tv_usec,
526 frm_len, hdr->trunc);
528 else
530 snprintf(hbuf, sizeof(hbuf),
531 "\n-- %s - isdnif:%d - frame:%6.6u - time:%2.2d.%2.2d %2.2d:%2.2d:%2.2d.%06u - length:%d ", ((hdr->dir) ? "NT->TE" : "TE->NT"),
532 hdr->isdnif, hdr->count, s->tm_mday, s->tm_mon + 1,
533 s->tm_hour, s->tm_min, s->tm_sec,
534 (u_int32_t)hdr->time.tv_usec, frm_len);
538 for (i = strlen(hbuf); i <= NCOLS;)
539 hbuf[i++] = '-';
541 hbuf[i++] = '\n';
542 hbuf[i] = '\0';
544 return(hbuf);
547 /*---------------------------------------------------------------------------*
548 * decode protocol and output to file(s)
549 *---------------------------------------------------------------------------*/
550 static void
551 dumpbuf(int n, unsigned char *dbuf, struct i4b_trace_hdr *hdr, int raw)
553 static char l1buf[128];
554 static unsigned char l2buf[32000];
555 static unsigned char l3buf[32000];
556 int cnt;
557 int nsave = n;
558 char *pbuf;
559 int i, j;
561 l1buf[0] = '\0';
562 l2buf[0] = '\0';
563 l3buf[0] = '\0';
565 switch (hdr->type)
567 case TRC_CH_I: /* Layer 1 INFO's */
569 /* on playback, don't display layer 1 if -i ! */
570 if (!(enable_trace & TRACE_I))
571 break;
573 pbuf = &l1buf[0];
575 switch (dbuf[0])
577 case INFO0:
578 sprintf((pbuf+strlen(pbuf)),"I430: INFO0 (No Signal)\n");
579 break;
581 case INFO1_8:
582 sprintf((pbuf+strlen(pbuf)),"I430: INFO1 (Activation Request, Priority = 8, from TE)\n");
583 break;
585 case INFO1_10:
586 sprintf((pbuf+strlen(pbuf)),"I430: INFO1 (Activation Request, Priority = 10, from TE)\n");
587 break;
589 case INFO2:
590 sprintf((pbuf+strlen(pbuf)),"I430: INFO2 (Pending Activation, from NT)\n");
591 break;
593 case INFO3:
594 sprintf((pbuf+strlen(pbuf)),"I430: INFO3 (Synchronized, from TE)\n");
595 break;
597 case INFO4_8:
598 sprintf((pbuf+strlen(pbuf)),"I430: INFO4 (Activated, Priority = 8/9, from NT)\n");
599 break;
601 case INFO4_10:
602 sprintf((pbuf+strlen(pbuf)),"I430: INFO4 (Activated, Priority = 10/11, from NT)\n");
603 break;
605 default:
606 sprintf((pbuf+strlen(pbuf)),"I430: ERROR, invalid INFO value 0x%x!\n", dbuf[0]);
607 break;
609 break;
611 case TRC_CH_D: /* D-channel data */
613 cnt = decode_lapd(l2buf, n, dbuf, hdr->dir, raw, print_q921);
615 n -= cnt;
616 dbuf += cnt;
618 if (n)
620 switch (*dbuf)
622 case 0x40:
623 case 0x41:
624 decode_1tr6(l3buf, n, cnt, dbuf, raw);
625 break;
627 case 0x08:
628 decode_q931(l3buf, n, cnt, dbuf, raw);
629 break;
631 default:
632 if (xopt)
634 l2buf[0] = '\0';
635 l3buf[0] = '\0';
637 else
639 decode_unknownl3(l3buf, n, cnt, dbuf, raw);
641 break;
644 break;
646 default: /* B-channel data */
648 pbuf = &l2buf[0];
650 for (i = 0; i < n; i += 16)
652 sprintf((pbuf+strlen(pbuf)),"B%d:%.3x ", hdr->type, i);
654 for (j = 0; j < 16; j++)
655 if (i + j < n)
656 sprintf((pbuf+strlen(pbuf)),"%02x ", dbuf[i + j]);
657 else
658 sprintf((pbuf+strlen(pbuf))," ");
660 sprintf((pbuf+strlen(pbuf))," ");
662 for (j = 0; j < 16 && i + j < n; j++)
663 if (isprint(dbuf[i + j]))
664 sprintf((pbuf+strlen(pbuf)),"%c", dbuf[i + j]);
665 else
666 sprintf((pbuf+strlen(pbuf)),".");
668 sprintf((pbuf+strlen(pbuf)),"\n");
670 break;
673 if (header && ((l1buf[0] != '\0' || l2buf[0] != '\0') || (l3buf[0] != 0)))
675 char *p;
676 p = fmt_hdr(hdr, nsave);
677 printf("%s", p);
678 if (outflag)
679 fprintf(Fout, "%s", p);
682 if (l1buf[0] != '\0')
684 printf("%s", l1buf);
685 if (outflag)
686 fprintf(Fout, "%s", l1buf);
689 if (l2buf[0] != '\0')
691 printf("%s", l2buf);
692 if (outflag)
693 fprintf(Fout, "%s", l2buf);
696 if (l3buf[0] != '\0')
698 printf("%s", l3buf);
699 if (outflag)
700 fprintf(Fout, "%s", l3buf);
704 /*---------------------------------------------------------------------------*
705 * exit handler function to be called at program exit
706 *---------------------------------------------------------------------------*/
707 void
708 exit_hdl()
710 if (traceon)
711 switch_driver(TRACE_OFF, Rx, Tx);
714 /*---------------------------------------------------------------------------*
715 * switch driver debugging output on/off
716 *---------------------------------------------------------------------------*/
717 static int
718 switch_driver(int value, int rx, int tx)
720 char buffer[80];
721 int v = value;
723 if (analyze == 0)
725 if (ioctl(f, I4B_TRC_SET, &v) < 0)
727 snprintf(buffer, sizeof(buffer),
728 "Error ioctl I4B_TRC_SET, val = %d", v);
729 perror(buffer);
730 return(-1);
733 else
735 if (value == TRACE_OFF)
737 if (ioctl(f, I4B_TRC_RESETA, &v) < 0)
739 snprintf(buffer, sizeof(buffer),
740 "Error ioctl I4B_TRC_RESETA - ");
741 perror(buffer);
742 return(-1);
745 else
747 i4b_trace_setupa_t tsa;
749 tsa.rxunit = rx;
750 tsa.rxflags = value;
751 tsa.txunit = tx;
752 tsa.txflags = value;
754 if (ioctl(f, I4B_TRC_SETA, &tsa) < 0)
756 snprintf(buffer, sizeof(buffer),
757 "Error ioctl I4B_TRC_SETA, val = %d", v);
758 perror(buffer);
759 return(-1);
763 return(0);
766 /*---------------------------------------------------------------------------*
767 * reopen files to support rotating logfile(s) on SIGUSR1
769 * based on an idea from Ripley (ripley@nostromo.in-berlin.de)
771 * close file and reopen it for append. this will be a nop
772 * if the previously opened file hasn't moved but will open
773 * a new one otherwise, thus enabling a rotation...
775 *---------------------------------------------------------------------------*/
776 static void
777 reopenfiles(int dummy)
779 if (outflag)
781 fclose(Fout);
783 add_datetime(outfilename, routfilename);
785 if ((Fout = fopen(routfilename, "a")) == NULL)
787 char buffer[80];
789 snprintf(buffer, sizeof(buffer),
790 "Error re-opening file [%s]", routfilename);
791 perror(buffer);
792 exit(1);
795 if ((setvbuf(Fout, (char *)NULL, _IONBF, 0)) != 0)
797 char buffer[80];
799 snprintf(buffer, sizeof(buffer),
800 "Error re-setting file [%s] to unbuffered",
801 routfilename);
802 perror(buffer);
803 exit(1);
807 if (Bopt)
810 fclose(BP);
812 add_datetime(BPfilename, rBPfilename);
814 if ((BP = fopen(rBPfilename, "a")) == NULL)
816 char buffer[80];
818 snprintf(buffer, sizeof(buffer),
819 "Error re-opening file [%s]", rBPfilename);
820 perror(buffer);
821 exit(1);
824 if ((setvbuf(BP, (char *)NULL, _IONBF, 0)) != 0)
826 char buffer[80];
828 snprintf(buffer, sizeof(buffer),
829 "Error re-setting file [%s] to unbuffered",
830 rBPfilename);
831 perror(buffer);
832 exit(1);
837 void
838 add_datetime(char *filename, char *rfilename)
840 time_t timeb;
841 struct tm *tmp;
842 FILE *fx;
844 time(&timeb);
845 tmp = localtime(&timeb);
847 snprintf(rfilename, sizeof(rfilename), "%s-", filename);
849 strftime(rfilename+strlen(rfilename), MAXPATHLEN-strlen(rfilename)-1,
850 "%Y%m%d-%H%M%S", tmp);
852 if ((fx = fopen(rfilename, "r")) != NULL)
854 fclose(fx);
856 sleep(1);
858 time(&timeb);
859 tmp = localtime(&timeb);
861 snprintf(rfilename, sizeof(rfilename), "%s-", filename);
863 strftime(rfilename+strlen(rfilename), MAXPATHLEN-strlen(rfilename)-1,
864 "%Y%m%d-%H%M%S", tmp);
868 /* EOF */