Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

c - which libc time gives me the time of day?

Fedora 33 Raku

I want to talk to lic.so.6 with NativeCall for an example I am writing. I have found

But I can't figure out which one will just give me the time of day (21:02:03)

Scratching my head,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In principle I shouldn't be trying to write an answer.[1] But some say impatience and/or hubris can be a virtue...

just give me the time of day (21:02:03)

The page you linked only lists functions that the introductory doc says have "no relation to the way people normally think of ... time".[3]


I looked at the module H?kon linked, and a module it uses: P5localtime. It includes this line:

my sub get-ctime(int64 is rw --> Str) is native is symbol<ctime> {*}

This calls the C function ctime that's documented on the Formatting Calendar Time page of the site you linked.

My guess is that you want to call the ctime_r function or similar.


I recall recently reading an exchange between yourself and someone knowledgeable about such things (ugexe?) about how you can specifically pick up glibc.so.6 rather than some other version, so I'll skip that wrinkle.

Footnotes

[1] I'm happy to give you the time of day, though it might not be the time of day you want. I know next to nothing about the relevant ingredients[2]. My only excuse for answering your question is that I sometimes have sufficient time and the sort of hubris and impatience to answer questions about topics I know nothing about that are not the virtues Larry meant.

[2] I don't recall using C to get any production code written. I don't know the libc time functions. I've only used NativeCall to do a few trivial things like some 'hello world' tests I recall doing when I read this blog post.

[3] The page you're looking at -- Getting the time -- presumably sounds promising to you, but if you go up a few levels in the web site you'll come to a page titled Time Basics that strongly suggests to me that you want to use functions from either the Formatting Calendar Time page or the Broken-down Time page.[4]

[4] Though I do have doubts. First, I don't know what I'm talking about.[2] Second, each of the functions has annotations like this that are troubling:

AS-Unsafe heap lock

I'll leave it up to you to read the POSIX Safety Concepts doc that explains those terms, so you can adapt accordingly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...