From fb5cccb2df60361a18fe3fd572b0fe18f3a4331c Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 9 Jan 2005 18:00:00 +0100 Subject: =?UTF-8?q?Version=201.3.18=20-=20Removed=20an=20unused=20variable?= =?UTF-8?q?=20from=20cTimer::GetWDayFromMDay()=20(thanks=20to=20Wayne=20Ke?= =?UTF-8?q?er=20=20=20for=20reporting=20this=20one).=20-=20Some=20more=20c?= =?UTF-8?q?hanges=20to=20the=20'childTid'=20handling=20in=20cThread=20(bas?= =?UTF-8?q?ed=20on=20suggestions=20by=20=20=20Stefan=20Huelswitt).=20-=20F?= =?UTF-8?q?ixed=20the=20spelling=20of=20'canceling'=20(thanks=20to=20Wayne?= =?UTF-8?q?=20Keer=20for=20reporting=20this=20one).=20-=20Re-introduced=20?= =?UTF-8?q?a=20sleep=20to=20cDvbPlayer::Action()=20to=20avoid=20high=20CPU?= =?UTF-8?q?=20load=20in=20still=20=20=20picture=20mode=20(thanks=20to=20Re?= =?UTF-8?q?inhard=20Nissl=20for=20reporting=20this=20one).=20-=20Fixed=20a?= =?UTF-8?q?=20possible=20race=20condition=20in=20generating=20the=20DVB=20?= =?UTF-8?q?device=20names=20(thanks=20to=20=20=20Rainer=20Zocholl=20for=20?= =?UTF-8?q?reporting=20this=20one).=20-=20Changed=20the=20way=20PES=20pack?= =?UTF-8?q?ets=20are=20played=20to=20allow=20replay=20of=20AC3=20sound=20o?= =?UTF-8?q?ver=20the=20=20=20full=20featured=20DVB=20cards=20(partially=20?= =?UTF-8?q?based=20on=20a=20patch=20from=20Werner=20Fink).=20=20=20+=20The?= =?UTF-8?q?=20new=20function=20cDevice::PlayPes()=20is=20now=20called=20wi?= =?UTF-8?q?th=20the=20complete=20PES=20data=20=20=20=20=20stream=20and=20c?= =?UTF-8?q?alls=20PlayVideo()=20and=20PlayAudio()=20as=20necessary.=20=20?= =?UTF-8?q?=20+=20cDevice::PlayVideo()=20is=20now=20only=20called=20with?= =?UTF-8?q?=20actual=20video=20PES=20packets.=20=20=20+=20cDevice::PlayAud?= =?UTF-8?q?io()=20is=20now=20called=20with=20the=20actual=20audio=20PES=20?= =?UTF-8?q?packets,=20which=20=20=20=20=20can=20be=20either=20"normal"=20a?= =?UTF-8?q?udio=20or=20AC3=20data.=20You=20need=20at=20least=20firmware=20?= =?UTF-8?q?version=20=20=20=20=200x261d=20to=20replay=20AC3=20sound=20over?= =?UTF-8?q?=20a=20full=20featured=20DVB=20card.=20This=20function=20now=20?= =?UTF-8?q?=20=20=20=20has=20an=20'int'=20return=20value.=20=20=20+=20Play?= =?UTF-8?q?Audio()=20of=20derived=20cDevice=20classes=20shall=20no=20longe?= =?UTF-8?q?r=20call=20the=20base=20class=20=20=20=20=20function.=20It=20sh?= =?UTF-8?q?all=20just=20play=20the=20given=20data=20as=20audio.=20=20=20+?= =?UTF-8?q?=20cPlayer::PlayVideo()=20and=20cPlayer::PlayAudio()=20are=20no?= =?UTF-8?q?w=20obsolete=20and=20have=20been=20=20=20=20=20replaced=20with?= =?UTF-8?q?=20cPlayer::PlayPes().=20=20=20+=20All=20StripAudioPackets()=20?= =?UTF-8?q?functions=20are=20now=20obsolete.=20The=20functionality=20has?= =?UTF-8?q?=20been=20=20=20=20=20moved=20into=20cDevice::PlayPes(),=20wher?= =?UTF-8?q?e=20only=20the=20video=20and=20audio=20packets=20that=20are=20?= =?UTF-8?q?=20=20=20=20actually=20required=20will=20be=20processed.=20=20?= =?UTF-8?q?=20+=20All=20audio=20track=20handling=20is=20now=20done=20by=20?= =?UTF-8?q?cDevice;=20cTransfer=20and=20cDvbPlayer=20no=20=20=20=20=20long?= =?UTF-8?q?er=20care=20about=20audio=20tracks.=20cPlayer,=20however,=20sti?= =?UTF-8?q?ll=20has=20the=20virtual=20hooks=20=20=20=20=20for=20audio=20tr?= =?UTF-8?q?ack=20handling=20in=20order=20to=20allow=20plugins=20to=20imple?= =?UTF-8?q?ment=20players=20that=20=20=20=20=20have=20their=20own=20idea?= =?UTF-8?q?=20about=20this.=20=20=20+=20cChannel::[AD]pid[12]()=20have=20b?= =?UTF-8?q?een=20replaced=20with=20cChannel::[AD]pid(int=20i)=20to=20=20?= =?UTF-8?q?=20=20=20allow=20access=20to=20all=20available=20PIDs.=20-=20Es?= =?UTF-8?q?caped=20the=20'-'=20and=20'=C3=B6'=20characters=20in=20the=20ma?= =?UTF-8?q?n=20pages=20(thanks=20to=20Darren=20Salt=20for=20=20=20pointing?= =?UTF-8?q?=20this=20out).=20-=20Completed=20the=20Italian=20OSD=20texts?= =?UTF-8?q?=20(thanks=20to=20Sean=20Carlos).=20-=20Fixed=20setting=20'sync?= =?UTF-8?q?ed'=20in=20cRemux=20when=20recording=20radio=20channels=20(than?= =?UTF-8?q?ks=20to=20=20=20Laurence=20Abbott).=20-=20Removed=20the=20LOCK?= =?UTF-8?q?=5FTHREAD=20from=20the=20LIRC=20thread=20(thanks=20to=20Ludwig?= =?UTF-8?q?=20Nussel).=20-=20Fixed=20genfontfile.c=20(sometimes=20the=20ch?= =?UTF-8?q?aracter=20width=20was=20wrong,=20and=20the=20codes=20were=20=20?= =?UTF-8?q?=20shifted=20one=20too=20far=20to=20the=20left).=20-=20Fixed=20?= =?UTF-8?q?the=20character=20width=20and=20shifted=20the=20codes=20one=20t?= =?UTF-8?q?o=20the=20right=20in=20all=20font=20=20=20files.=20-=20Renamed?= =?UTF-8?q?=20font=3F=3F=3F.c=20to=20font=3F=3F=3F-iso8859-1.c=20for=20sym?= =?UTF-8?q?metry.=20-=20Switched=20the=20character=20set=20to=20iso8859-15?= =?UTF-8?q?=20for=20English,=20German=20and=20Finnish=20(thanks=20=20=20to?= =?UTF-8?q?=20Andreas=20Brugger=20for=20reporting=20the=20missing=20Euro?= =?UTF-8?q?=20sign=20in=20iso8859-1).=20-=20Added=20'channels.conf.terr'?= =?UTF-8?q?=20entries=20for=20L=C3=BCbeck=20(thanks=20to=20Stefan=20Hu?= =?UTF-8?q?=C3=9Ffeldt).=20-=20Fixed=20a=20race=20condition=20in=20startin?= =?UTF-8?q?g=20a=20thread=20(thanks=20to=20Reinhard=20Nissl=20for=20=20=20?= =?UTF-8?q?reporting=20this=20one).=20-=20Replaced=20non-threadsafe=20libr?= =?UTF-8?q?ary=20functions=20with=20their=20threadsafe=20versions=20(thank?= =?UTF-8?q?s=20=20=20to=20Rainer=20Zocholl=20for=20pointing=20this=20out).?= =?UTF-8?q?=20-=20Other=20non-threadsafe=20functions=20have=20been=20repla?= =?UTF-8?q?ced=20by=20threadsafe=20classes=20that=20hide=20=20=20the=20act?= =?UTF-8?q?ual=20buffering.=20In=20particular=20these=20are:=20=20=20readd?= =?UTF-8?q?ir()=20->=20cReadDir=20=20=20readline()=20->=20cReadLine=20-=20?= =?UTF-8?q?Several=20formerly=20non-threadsafe=20functions=20now=20have=20?= =?UTF-8?q?a=20return=20type=20of=20cString:=20=20=20cChannel::ToText()=20?= =?UTF-8?q?=20=20tChannelID::ToString()=20=20=20cEvent::GetDateString()=20?= =?UTF-8?q?=20=20cEvent::GetTimeString()=20=20=20cEvent::GetEndTimeString(?= =?UTF-8?q?)=20=20=20cEvent::GetVpsString()=20=20=20cMark::ToText()=20=20?= =?UTF-8?q?=20cTimer::ToText()=20=20=20cSource::ToString()=20=20=20cTimer:?= =?UTF-8?q?:PrintDay()=20=20=20cTimer::PrintFirstDay()=20=20=20PrefixVideo?= =?UTF-8?q?FileName()=20=20=20IndexToHMSF()=20=20=20ChannelString()=20=20?= =?UTF-8?q?=20strescape()=20=20=20AddDirectory()=20=20=20itoa()=20=20=20We?= =?UTF-8?q?ekDayName()=20=20=20DayDateTime()=20=20=20When=20using=20these?= =?UTF-8?q?=20functions=20in=20a=20'const=20char=20*'=20context=20there=20?= =?UTF-8?q?is=20nothing=20special=20=20=20to=20consider,=20except=20that?= =?UTF-8?q?=20you=20can=20no=20longer=20have=20a=20pointer=20to=20the=20re?= =?UTF-8?q?turn=20value,=20=20=20as=20in=20=20=20const=20char=20*date=20?= =?UTF-8?q?=3D=20DayDateTime();=20=20=20Although=20this=20will=20compile?= =?UTF-8?q?=20without=20error=20message,=20the=20resulting=20'date'=20will?= =?UTF-8?q?=20not=20=20=20be=20valid=20after=20this=20line.=20Use=20this?= =?UTF-8?q?=20instead:=20=20=20cString=20date=20=3D=20DayDateTime();=20=20?= =?UTF-8?q?=20In=20a=20'const=20void=20*'=20context=20(as=20in=20printf()?= =?UTF-8?q?=20etc.)=20the=20result=20needs=20to=20be=20=20=20dereferenced?= =?UTF-8?q?=20with=20a=20'*',=20as=20in=20=20=20printf("%s",=20*DayDateTim?= =?UTF-8?q?e());=20=20=20to=20make=20it=20a=20'const=20char=20*'.=20-=20Re?= =?UTF-8?q?moved=20delay=5Fms(),=20using=20cCondWait::SleepMs()=20instead.?= =?UTF-8?q?=20-=20Replaced=20time=5Fms()=20with=20a=20threadsafe=20and=20n?= =?UTF-8?q?on-overflowing=20cTimeMs=20(thanks=20to=20Rainer=20=20=20Zochol?= =?UTF-8?q?l=20for=20pointing=20out=20this=20problem).=20-=20Added=20cDevi?= =?UTF-8?q?ce::mutexReceiver=20to=20avoid=20a=20race=20condition=20when=20?= =?UTF-8?q?attaching/detaching=20=20=20receivers=20from=20different=20thre?= =?UTF-8?q?ads.=20-=20The=20new=20remote=20control=20button=20"Audio"=20ca?= =?UTF-8?q?n=20be=20used=20to=20switch=20between=20different=20=20=20audio?= =?UTF-8?q?=20tracks.=20The=20"Green"=20button=20in=20the=20"Main"=20menu?= =?UTF-8?q?=20has=20been=20changed=20from=20"Language"=20=20=20to=20"Audio?= =?UTF-8?q?",=20since=20it=20now=20also=20controls=20switching=20between?= =?UTF-8?q?=20normal=20and=20Dolby=20Digital=20=20=20audio=20tracks=20(see?= =?UTF-8?q?=20MANUAL=20for=20details).=20-=20The=20description=20of=20the?= =?UTF-8?q?=20audio=20tracks=20is=20now=20taken=20from=20the=20"component?= =?UTF-8?q?=20descriptors"=20=20=20that=20are=20broadcast=20in=20the=20EPG?= =?UTF-8?q?=20data.=20However=20(as=20no=20big=20surprise),=20not=20all=20?= =?UTF-8?q?channels=20=20=20actually=20provide=20useful=20data=20here,=20s?= =?UTF-8?q?o=20there=20are=20now=20some=20additional=20EPG=20bugfixes,=20?= =?UTF-8?q?=20=20which=20can=20be=20activated=20by=20setting=20the=20"EPG?= =?UTF-8?q?=20bugfix=20level"=20to=203.=20-=20The=20format=20of=20the=20'e?= =?UTF-8?q?pg.data'=20files=20has=20been=20extended=20by=20the=20new=20tag?= =?UTF-8?q?=20'X',=20which=20=20=20contains=20the=20stream=20components=20?= =?UTF-8?q?of=20an=20event=20(see=20man=20vdr(5)=20for=20details).=20-=20T?= =?UTF-8?q?he=20cStatus=20class=20now=20has=20the=20new=20member=20functio?= =?UTF-8?q?n=20SetAudioTrack(),=20which=20can=20be=20=20=20used=20to=20get?= =?UTF-8?q?=20notified=20when=20the=20audio=20track=20has=20been=20switche?= =?UTF-8?q?d,=20and=20the=20new=20member=20=20=20function=20SetAudioChanne?= =?UTF-8?q?l()=20which=20is=20called=20when=20the=20audio=20channel=20is?= =?UTF-8?q?=20changed.=20-=20Skins=20need=20to=20implement=20the=20new=20c?= =?UTF-8?q?SkinDisplayTrack=20class=20to=20display=20the=20audio=20=20=20t?= =?UTF-8?q?rack=20menu.=20-=20The=20ST:TNG=20skin=20now=20displays=20the?= =?UTF-8?q?=20current=20audio=20track=20description=20(if=20any)=20at=20th?= =?UTF-8?q?e=20=20=20botton=20left=20side.=20-=20The=20new=20setup=20optio?= =?UTF-8?q?n=20"DVB/Audio=20languages"=20can=20be=20used=20to=20control=20?= =?UTF-8?q?which=20audio=20=20=20language=20shall=20be=20selected=20in=20c?= =?UTF-8?q?ase=20a=20channel=20broadcasts=20in=20different=20languages=20?= =?UTF-8?q?=20=20(see=20MANUAL=20for=20details).=20-=20The=20"Left"=20and?= =?UTF-8?q?=20"Right"=20keys=20in=20the=20"Audio"=20menu=20can=20be=20used?= =?UTF-8?q?=20to=20switch=20between=20=20=20the=20left=20and=20right=20ste?= =?UTF-8?q?reo=20channels=20in=20case=20there=20are=20different=20audio=20?= =?UTF-8?q?tracks=20=20=20in=20these=20channels=20(see=20MANUAL=20for=20de?= =?UTF-8?q?tails).=20-=20Fixed=20a=20possible=20race=20condition=20in=20cD?= =?UTF-8?q?evice::Action()=20(thanks=20to=20Mattias=20Gr=C3=B6nlund).=20-?= =?UTF-8?q?=20Fixed=20the=20default=20quality=20value=20when=20grabbing=20?= =?UTF-8?q?a=20JPEG=20image=20(thanks=20to=20Patrick=20=20=20Gleichmann).?= =?UTF-8?q?=20-=20Fixed=20deleting=20a=20menu=20item=20in=20case=20the=20n?= =?UTF-8?q?ext=20item=20is=20not=20selectable=20(thanks=20to=20=20=20Dino?= =?UTF-8?q?=20Ravnic).=20-=20Implemented=20displaying=20mandatory=20subtit?= =?UTF-8?q?les=20in=20the=20SPU=20decoder=20(thanks=20to=20Marco=20=20=20S?= =?UTF-8?q?chl=C3=BC=C3=9Fler).=20-=20The=20setup=20option=20"Recording/Re?= =?UTF-8?q?cord=20Dolby=20Digital"=20has=20been=20renamed=20and=20moved=20?= =?UTF-8?q?to=20=20=20"DVB/Use=20Dolby=20Digital".=20It=20now=20controls?= =?UTF-8?q?=20whether=20Dolby=20Digital=20is=20recorded=20and=20=20=20whet?= =?UTF-8?q?her=20an=20available=20DD=20audio=20track=20will=20appear=20in?= =?UTF-8?q?=20the=20"Audio"=20menu.=20-=20Added=20support=20for=20circular?= =?UTF-8?q?=20polarization=20(thanks=20to=20Jonan=20Santiago).=20-=20Thank?= =?UTF-8?q?s=20to=20Werner=20Fink,=20Reinhard=20Nissl,=20Sascha=20Volkenan?= =?UTF-8?q?dt=20and=20Bj=C3=B8rnar=20Nilsen=20for=20=20=20their=20support?= =?UTF-8?q?=20in=20testing=20and=20fine=20tuning=20this=20version.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools.c | 173 ++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 115 insertions(+), 58 deletions(-) (limited to 'tools.c') diff --git a/tools.c b/tools.c index 41d0c72..af2a73c 100644 --- a/tools.c +++ b/tools.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.82 2004/11/21 14:36:34 kls Exp $ + * $Id: tools.c 1.87 2005/01/04 11:06:45 kls Exp $ */ #include "tools.h" @@ -65,18 +65,6 @@ void writechar(int filedes, char c) safe_write(filedes, &c, sizeof(c)); } -char *readline(FILE *f) -{ - static char buffer[MAXPARSEBUFFER]; - if (fgets(buffer, sizeof(buffer), f) > 0) { - int l = strlen(buffer) - 1; - if (l >= 0 && buffer[l] == '\n') - buffer[l] = 0; - return buffer; - } - return NULL; -} - char *strcpyrealloc(char *dest, const char *src) { if (src) { @@ -167,15 +155,15 @@ char *compactspace(char *s) return s; } -const char *strescape(const char *s, const char *chars) +cString strescape(const char *s, const char *chars) { - static char *buffer = NULL; + char *buffer; const char *p = s; char *t = NULL; while (*p) { if (strchr(chars, *p)) { if (!t) { - buffer = (char *)realloc(buffer, 2 * strlen(s) + 1); + buffer = MALLOC(char, 2 * strlen(s) + 1); t = buffer + (p - s); s = strcpy(buffer, s); } @@ -222,25 +210,6 @@ int numdigits(int n) return strlen(buf); } -int time_ms(void) -{ - static time_t t0 = 0; - struct timeval t; - if (gettimeofday(&t, NULL) == 0) { - if (t0 == 0) - t0 = t.tv_sec; // this avoids an overflow (we only work with deltas) - return (t.tv_sec - t0) * 1000 + t.tv_usec / 1000; - } - return 0; -} - -void delay_ms(int ms) -{ - int t0 = time_ms(); - while (time_ms() - t0 < ms) - ; -} - bool isnumber(const char *s) { if (!*s) @@ -253,18 +222,17 @@ bool isnumber(const char *s) return true; } -const char *itoa(int n) +cString AddDirectory(const char *DirName, const char *FileName) { - static char buf[16]; - snprintf(buf, sizeof(buf), "%d", n); + char *buf; + asprintf(&buf, "%s/%s", DirName && *DirName ? DirName : ".", FileName); return buf; } -const char *AddDirectory(const char *DirName, const char *FileName) +cString itoa(int n) { - static char *buf = NULL; - free(buf); - asprintf(&buf, "%s/%s", DirName && *DirName ? DirName : ".", FileName); + char buf[16]; + snprintf(buf, sizeof(buf), "%d", n); return buf; } @@ -336,10 +304,10 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks) struct stat st; if (stat(FileName, &st) == 0) { if (S_ISDIR(st.st_mode)) { - DIR *d = opendir(FileName); - if (d) { + cReadDir d(FileName); + if (d.Ok()) { struct dirent *e; - while ((e = readdir(d)) != NULL) { + while ((e = d.Next()) != NULL) { if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) { char *buffer; asprintf(&buffer, "%s/%s", FileName, e->d_name); @@ -367,7 +335,6 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks) free(buffer); } } - closedir(d); } else { LOG_ERROR_STR(FileName); @@ -389,11 +356,11 @@ bool RemoveFileOrDir(const char *FileName, bool FollowSymlinks) bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis) { - DIR *d = opendir(DirName); - if (d) { + cReadDir d(DirName); + if (d.Ok()) { bool empty = true; struct dirent *e; - while ((e = readdir(d)) != NULL) { + while ((e = d.Next()) != NULL) { if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..") && strcmp(e->d_name, "lost+found")) { char *buffer; asprintf(&buffer, "%s/%s", DirName, e->d_name); @@ -414,7 +381,6 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis) free(buffer); } } - closedir(d); if (RemoveThis && empty) { dsyslog("removing %s", DirName); if (remove(DirName) < 0) { @@ -451,7 +417,7 @@ char *ReadLink(const char *FileName) bool SpinUpDisk(const char *FileName) { - static char *buf = NULL; + char *buf = NULL; for (int n = 0; n < 10; n++) { free(buf); if (DirectoryOk(FileName)) @@ -471,12 +437,14 @@ bool SpinUpDisk(const char *FileName) double seconds = (((long long)tp2.tv_sec * 1000000 + tp2.tv_usec) - ((long long)tp1.tv_sec * 1000000 + tp1.tv_usec)) / 1000000.0; if (seconds > 0.5) dsyslog("SpinUpDisk took %.2f seconds\n", seconds); + free(buf); return true; } else LOG_ERROR_STR(buf); } } + free(buf); esyslog("ERROR: SpinUpDisk failed"); return false; } @@ -489,37 +457,108 @@ time_t LastModifiedTime(const char *FileName) return 0; } -const char *WeekDayName(int WeekDay) +// --- cTimeMs --------------------------------------------------------------- + +cTimeMs::cTimeMs(void) +{ + Set(); +} + +uint64 cTimeMs::Now(void) +{ + struct timeval t; + if (gettimeofday(&t, NULL) == 0) + return (uint64(t.tv_sec)) * 1000 + t.tv_usec / 1000; + return 0; +} + +void cTimeMs::Set(int Ms) +{ + begin = Now() + Ms; +} + +bool cTimeMs::TimedOut(void) +{ + return Now() >= begin; +} + +uint64 cTimeMs::Elapsed(void) { - static char buffer[4]; + return Now() - begin; +} + +// --- cString --------------------------------------------------------------- + +cString::cString(const char *S) +{ + s = S ? strdup(S) : NULL; +} + +cString::~cString() +{ + free(s); +} + +cString &cString::operator=(const cString &String) +{ + s = String.s ? strdup(String.s) : NULL; + return *this; +} + +cString WeekDayName(int WeekDay) +{ + char buffer[4]; WeekDay = WeekDay == 0 ? 6 : WeekDay - 1; // we start with monday==0! if (0 <= WeekDay && WeekDay <= 6) { const char *day = tr("MonTueWedThuFriSatSun"); day += WeekDay * 3; - strncpy(buffer, day, 3); + strn0cpy(buffer, day, sizeof(buffer)); return buffer; } else return "???"; } -const char *WeekDayName(time_t t) +cString WeekDayName(time_t t) { struct tm tm_r; return WeekDayName(localtime_r(&t, &tm_r)->tm_wday); } -const char *DayDateTime(time_t t) +cString DayDateTime(time_t t) { - static char buffer[32]; + char buffer[32]; if (t == 0) time(&t); struct tm tm_r; tm *tm = localtime_r(&t, &tm_r); - snprintf(buffer, sizeof(buffer), "%s %2d.%02d %02d:%02d", WeekDayName(tm->tm_wday), tm->tm_mday, tm->tm_mon + 1, tm->tm_hour, tm->tm_min); + snprintf(buffer, sizeof(buffer), "%s %2d.%02d %02d:%02d", *WeekDayName(tm->tm_wday), tm->tm_mday, tm->tm_mon + 1, tm->tm_hour, tm->tm_min); return buffer; } +cString TimeToString(time_t t) +{ + char buffer[32]; + if (ctime_r(&t, buffer)) { + buffer[strlen(buffer) - 1] = 0; // strip trailing newline + return buffer; + } + return "???"; +} + +// --- cReadLine ------------------------------------------------------------- + +char *cReadLine::Read(FILE *f) +{ + if (fgets(buffer, sizeof(buffer), f) > 0) { + int l = strlen(buffer) - 1; + if (l >= 0 && buffer[l] == '\n') + buffer[l] = 0; + return buffer; + } + return NULL; +} + // --- cPoller --------------------------------------------------------------- cPoller::cPoller(int FileHandle, bool Out) @@ -557,6 +596,24 @@ bool cPoller::Poll(int TimeoutMs) return false; } +// --- cReadDir -------------------------------------------------------------- + +cReadDir::cReadDir(const char *Directory) +{ + directory = opendir(Directory); +} + +cReadDir::~cReadDir() +{ + if (directory) + closedir(directory); +} + +struct dirent *cReadDir::Next(void) +{ + return directory && readdir_r(directory, &u.d, &result) == 0 ? result : NULL; +} + // --- cFile ----------------------------------------------------------------- bool cFile::files[FD_SETSIZE] = { false }; -- cgit v1.2.3