0

I can easily convert kernel data type struct rtc_time to string with help sprintf(), but I can't do reverse operation:

 string "Thu Aug 23 14:55:02 2001" to rtc_time structure

Should I write my own realisation if strptime() function into my kernel module?

Could anyone prompt me?

0andriy
  • 4,183
  • 1
  • 24
  • 37
Anisyanka
  • 63
  • 8
  • Yes, for printing we have `%ptR` extension, but for parsing there is nothing in kernel. Why do you need one? – 0andriy Mar 03 '20 at 20:48
  • @0andriy , I write a driver for a rtc i2c chip and I have exported some attributes to sysfs for ability to enable/disable alarm interrupts. To set interrupt time i should do: ```echo "Thu Aug 23 00:03:02 2020" >> /sys/class/rtc/rtc0/device/alarm_time" ``` After this my attribute method `store` will be called, and I must convert this string to rtc_time structure – Anisyanka Mar 03 '20 at 21:07
  • Why would you have an interface that allows inconsistent input (i.e. a day-of-week and date)? Why not use an all-numeric format such the **date** shell command? – sawdust Mar 04 '20 at 00:17
  • @sawdust, i use `hwclock` and the one gives me time as: ```Fri Feb 14 01:25:41 2020 0.000000 seconds``` – Anisyanka Mar 04 '20 at 08:11
  • Your reasoning is flawed. Why would you use the output of `hwclock` (i.e. the *current* time) to set an alarm time (e.g. a *future* time)? – sawdust Mar 04 '20 at 08:44
  • @sawdust, No, i don't use hwclock output to set alarm. Maybe I confused you, excuse me:) I use hwclock like an user space utility with help which I can read/write usual time to/from my rtc chip. hwclock gives time in this format ```Fri Feb 14 01:25:41 2020```. I use sysfs attributes to set alarm time. – Anisyanka Mar 04 '20 at 08:57
  • I just wanted to do input forman for sysfs like the output format of hwclock. F.e ```echo "Thu Aug 23 00:03:02 2020" >> /sys/class/rtc/rtc0/device/alarm_time"``` But i can use anyone data format for my own attribute – Anisyanka Mar 04 '20 at 09:01
  • RTC subsystem has its own ABI, don't do custom one, except the case if you are just learning to program in kernel. https://www.kernel.org/doc/html/latest/admin-guide/rtc.html – 0andriy Mar 04 '20 at 10:01
  • Thank you for this link. I will learn it. Yes, you have guessed, i am a new in kernel/driver programming – Anisyanka Mar 04 '20 at 11:14

0 Answers0