Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7981213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:18:08+00:00 2026-06-04T10:18:08+00:00

Learning C and I’m trying to get a visual comparison of the variable types

  • 0

Learning C and I’m trying to get a visual comparison of the variable types and sizes that are returned by stat() for the atime/mtime attributes and for the nsec precision values.

I’m running stat() on a file and want to get the mtime and mtime nsec values from the returned stat structure and then store these values in separate variables (which I then want to pass to utimes()… long story!).
According to http://www.kernel.org/doc/man-pages/online/pages/man2/stat.2.html#NOTES I can get the value from st_mtim.tv_nsec or st_mtimensec depending on various OS/build conditions. In my actual program I’ll check for both and use whichever is set, or just fallback to the normal second precision of st_mtime

What variable type and size do I need to declare in order to store a normal timestamp as returned by st_mtime?

What variable type and size do I need to declare to store an nsec value from st_mtim.tv_nsec or st_mtimensec?
Are these a decimal, including the number of whole seconds of the time? Or do they just return the nsec portion of the time?

Do I need to declare different variable sizes for the nsecs depending on my system’s architecture?

And finally, what conversion specifiers do I need for outputting these variables using printf()?

Cheers, B

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:18:09+00:00Added an answer on June 4, 2026 at 10:18 am
    1. st_mtime should be a time_t.
    2. According to POSIX <time.h>, the type of tv_nsec is just long.
    3. The fields like st_mtim.tv_nsec will return the number of nanoseconds.
    4. For the long, you need l; for time_t, it is not clearly defined, AFAIK.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Learning java server technologies, trying to clarify some things. There are few technologies that
For learning purposes, I'm trying to make a function using Python that takes in
Learning ruby. I'm under the impression that boolean attributes should be named as follows:
Learning C#, WPF. Currently trying to get to grips with Dispatchers, specifically between threads
Learning Jenkins, and trying to get it to build a project for which my
Still learning lxml. I discovered that sometimes I cannot get to the text of
Learning how to test is HARD! I'm just trying to get MiniTest running and
Learning a lot in my few years of programming that the best projects are
When learning C# for the first time, I was astonished that they had no
I learning Perl and I want to create a simple application that gets all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.