comparison util.c @ 511:291e3caa91a0

Move logParseFilename() to nn_log_parse_filename() under util.c and rename logFileOpen() and logFileClose().
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jun 2012 19:28:34 +0300
parents b6f6c989deab
children ef5a2aa8382b
comparison
equal deleted inserted replaced
510:54f4f84bae5c 511:291e3caa91a0
716 void nn_strtuple_free(nn_strtuple_t *tuple) 716 void nn_strtuple_free(nn_strtuple_t *tuple)
717 { 717 {
718 th_free(tuple->str); 718 th_free(tuple->str);
719 th_free(tuple); 719 th_free(tuple);
720 } 720 }
721
722
723 #define VPUTCH(CH) th_vputch(&bufData, &bufSize, &bufLen, CH)
724 #define VPUTS(STR) th_vputs(&bufData, &bufSize, &bufLen, STR)
725
726 char *nn_log_parse_filename(const char *fmt, int id)
727 {
728 size_t bufSize = strlen(fmt) + TH_BUFGROW, bufLen = 0;
729 char *bufData = th_malloc(bufSize);
730 char tmpBuf[32];
731 const char *s = fmt;
732
733 while (*s)
734 {
735 if (*s == '%')
736 {
737 s++;
738 switch (*s)
739 {
740 case 'i':
741 snprintf(tmpBuf, sizeof(tmpBuf), "%05d", id);
742 VPUTS(tmpBuf);
743 break;
744
745 case 'd':
746 snprintf(tmpBuf, sizeof(tmpBuf), "%d", id);
747 VPUTS(tmpBuf);
748 break;
749
750 case '%':
751 VPUTCH('%');
752 break;
753 }
754 s++;
755 }
756 else
757 {
758 VPUTCH(*s);
759 s++;
760 }
761 }
762
763 VPUTCH(0);
764 return bufData;
765 }