سؤال

I am writing a tool to log battery charge to a CSV file (I know it'd be a bash one-liner but this is yet another Common Lisp learning exercise for me).

My plan is to slurp the entire battery state file into memory, as it's guaranteed to be a tiny file. But file-length is consistently returning 0 for the file size, while working normally on other files:

* (defun stream-length (path)
    (with-open-file (stream path) 
            (file-length stream)))

STYLE-WARNING: redefining COMMON-LISP-USER::STREAM-LENGTH in DEFUN

STREAM-LENGTH
* (stream-length "/home/duncan/foo")

4
* (stream-length "/proc/acpi/battery/BAT0/state")

0

It turns out it's not only SBCL; Perl behaves the same way:

$ perl -e 'print -s "/home/duncan/foo"; print "\n"'
4
$ perl -e 'print -s "/proc/acpi/battery/BAT0/state"; print "\n"'
0

But the file definitely contains something:

$ cat /proc/acpi/battery/BAT0/state
present:                 yes
capacity state:          ok
charging state:          discharging
present rate:            0 mW
remaining capacity:      3945 mWh
present voltage:         10800 mV

So I'm presuming there's something special about the state file. Could someone please enlighten me as to what it is?

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top