Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » LoadFile("/sys/devices/virtual/thermal/ ...") does not work
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work [message #58405 is a reply to message #58404] Wed, 18 May 2022 09:58 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13986
Registered: November 2005
Ultimate Member
OK, this should do the job:

String LoadFile(const char *filename) {
	FindFile ff(filename);
	if(ff && ff.IsFile()) {
	#ifdef PLATFORM_POSIX
		if(ff.GetLength() == 0) { // handle special cases like /proc/...
			int fd = open(filename,O_RDONLY);
			if(fd >= 0) {
				const int CHUNK = 32768;
				StringBuffer s;
				for(;;) {
					int n = s.GetCount();
					s.SetCount(n + CHUNK);
					int len = read(fd, ~s + n, CHUNK);
					if(len != CHUNK) {
						if(len > 0)
							s.SetCount(n + len);
						return s;
					}
				}
			}
			return String::GetVoid();
		}
	#endif
		FileIn in(filename);
		return LoadStream(in);
	}
	return String::GetVoid();
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: BiArray::Create{Head,Tail} with variadic args
Next Topic: Serialize long as uint64 on some platforms
Goto Forum:
  


Current Time: Sun Jun 23 03:06:03 CEST 2024

Total time taken to generate the page: 0.01438 seconds