-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libc: minimal: implement time() API #33397
libc: minimal: implement time() API #33397
Conversation
03749ff
to
0a8e473
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be:
Upon successful completion, time() shall return the value of time. Otherwise, (time_t)-1 shall be returned.
0a8e473
to
6d38291
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be perfect if there is also a test case added in tests/lib/c_lib/src/main.c.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lib/libc/minimal/source/time/time.c
Outdated
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <posix/time.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is included for just clock_gettime prototype, I'd suggest to include a comment on that. Because otherwise it's a bit strange dependency, which can lead to further include dependency hell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is for clock_gettime()
prototype. You mean dependency hell because posix/time.h
might fetch time.h
or the other way around? Fortunately, this is just a C source file, not a header file, so I was not expecting any problems with dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nonetheless, the include should be conditional as it's pulling in something that isn't part of libc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional on what? CONFIG_POSIX_CLOCK
? Currently whole file is compiled only when CONFIG_POSIX_CLOCK=y
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean dependency hell because posix/time.h
Because posix/time.h is a full POSIX header which might have/pull things which aren't available in minimal libc or done differently (incompatibly) in it. Put it differently, at any time compiling this source file may break. Some time ago, I spent a lot of effort to straighten up dependencies between minlibc/newlib/posix, and that wasn't even done completely, and this patch is kinda retrograde action in that regard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional on what?
CONFIG_POSIX_CLOCK
? Currently whole file is compiled only whenCONFIG_POSIX_CLOCK=y
.
OK, then the comment is certainly desirable (because that dependency is not clear from the code).
#18892 is also relevant. It's not clear that this change is a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. I've added a comment, as suggested. Let me know if there is something more that I can do.
Implement time() API by using clock_gettime(CLOCK_REALTIME, ...). Signed-off-by: Marcin Niestroj <[email protected]>
6d38291
to
79d353b
Compare
I am not proper owner of this PR, so reassigning to @nashif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a test please.
Add test cases for time() function. Signed-off-by: Marcin Niestroj <[email protected]>
Implement time() API by using clock_gettime(CLOCK_REALTIME, ...).