0

When can the call to mktime in C program can return -1, assuming the value passed to it are valid only.

In documentation it is mentioned as If the calendar time cannot be represented as valid, a value of -1 is returned.

Is it possible if anyone can share code behind for this mktime function call to understand what can fail it?

P.S The environment is linux on m68k processor

8
  • 2
    Suggest posting the values of struct tm used. Commented Feb 4, 2014 at 15:38
  • 1
    you could search the source code here if it's not this: lxr.free-electrons.com/source/kernel/time.c#L322 Commented Feb 4, 2014 at 15:40
  • 1
    @chux: The question asks for a description of the situations that can cause an error; it is not asking about an error the OP has observed. Commented Feb 4, 2014 at 15:42
  • 1
    @HayriUğurKoltuk: That does not look like an implementation of the user-visible mktime because it neither normalizes the struct tm it is passed and sets the tm_wday and tm_yday components nor determines whether an error as occurred. I suspect it is a routine with the same name with a subset of the function intended solely for limited use inside the kernel. Commented Feb 4, 2014 at 15:47
  • @chux we believe set valid values in struct tm_sec,tm_min,tm_hour,tm_mon,tm_year,tm_mday. We have never been able to capture these value, when it fails , because it happens very random sometimes.:( Commented Feb 4, 2014 at 16:02

1 Answer 1

3

mktime may fail if the time represented by the struct tm it is passed is outside the range that can be represented by the time_t type.

Sign up to request clarification or add additional context in comments.

2 Comments

It probably could also fail if the struct tm is meaningless like e.g. a tm_mday of 42 or -17 ....(or a tm_mon of 12 or 131)
@BasileStarynkevitch: The documentation specifies that the fields may have values outside their normal ranges and that they are normalized by mktime.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.