f



function "strftime" produce "No such file or directory" error

Hello, everyone.
This is a test program that generates undesired results when cross 
compiling with eldk-4.0.
It is strange that localtime_r sets errno to ENOENT at the first time, 
but never again in the following calls, while strftime always sets errno 
to ENOENT.
But errno will never be set if run on Ubuntu 12.04.4, or Debian 7.
Can someone help me?

This is the output:
# ./test_timegen
1st errno = 0, Success
2nd errno = 2, No such file or directory
3rd errno = 2, No such file or directory
2000-01-05 04:12:11.661426
1st errno = 0, Success
2nd errno = 0, Success
3rd errno = 2, No such file or directory
2000-01-05 04:12:11.662134
1st errno = 0, Success
2nd errno = 0, Success
3rd errno = 2, No such file or directory
2000-01-05 04:12:11.662265
# uname -a
Linux ePM837x 2.6.25 #531 Tue Sep 13 09:35:34 PDT 2011 ppc unknown
# ldd --version | grep libc
ldd (GNU libc) 2.5
# cat /proc/cpuinfo | grep cpu
cpu             : e300c4
#

This is the cross compile command:
/opt/eldk-4.0/usr/bin/ppc_82xx-gcc test_timegen.c -lrt -o test_timegen

This is the source code test_timegen.c:
#include    <stdio.h>
#include    <stdlib.h>
#include    <string.h>
#include    <errno.h>
#include    <time.h>

static void print(const char *s) {
     fprintf(stderr, "%s errno = %d, %s\n", s, errno, strerror(errno));
     errno = 0;
}

void print_time() {
     const clockid_t clkid = CLOCK_REALTIME;
     struct tm tm_inst;
     char timebuf[64] = {0};
     struct timespec t;
     if (clock_gettime(clkid, &t) < 0) {
         perror("set_time");
         exit(1);
     }
     print("1st");
     if (localtime_r(&t.tv_sec, &tm_inst) == NULL) {
         perror("localtime_r");
         exit(1);
     }
     print("2nd");
     if (strftime(timebuf, sizeof(timebuf), "%F %T", &tm_inst) == 0) {
         perror("strftime");
         exit(1);
     }
     print("3rd");
     int len = strlen(timebuf);
     snprintf(timebuf+len, sizeof(timebuf)-len,
              ".%06ld", t.tv_nsec / 1000);
     fprintf(stderr, "%s\n", timebuf);
}

int main() {
     int j;
     for (j = 0; j < 3; j++)
         print_time();
     return 0;
}
0
wy
3/19/2014 7:34:51 AM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (349) is leader. Post Follow

5 Replies
507 Views

Similar Articles

[PageSpeed] 17

On Wednesday, March 19, 2014 12:34:51 AM UTC-7, wy wrote:
> This is a test program that generates undesired results when cross=20
> compiling with eldk-4.0.
> It is strange that localtime_r sets errno to ENOENT at the first time,=20
> but never again in the following calls, while strftime always sets errno=
=20
> to ENOENT.
> But errno will never be set if run on Ubuntu 12.04.4, or Debian 7.
> Can someone help me?

To quote the POSIX standard:
    Some functions provide the error number in a variable accessed through
    the symbol errno, defined by including the <errno.h> header. The value
    of errno should only be examined when it is indicated to be valid by a
    function's return value.
and
    Many functions provide an error number in errno, which has type int and
    is defined in <errno.h>. The value of errno shall be defined only after
    a call to a function for which it is explicitly stated to be set and
    until it is changed by the next function call or if the application
    assigns it a value. The value of errno should only be examined when it
    is indicated to be valid by a function's return value.

That is, the value of errno when a standard interface like clock_gettime() =
or localtime_r() *succeeds* is UNDEFINED.  It might tell you something abou=
t the internals of the involved function, but you can probably get that inf=
ormation more easily by reading the public source, or using the platforms's=
 system call or function tracing functionality, and it doesn't change the f=
act that the call has claimed to do what it should.

To put it another way: What problem are you trying to solve by looking at e=
rrno on *success*?


Philip Guenther

0
Philip
3/19/2014 8:02:45 AM
On 2014-03-19, wy <warmyouth@gmail.com> wrote:
> It is strange that localtime_r sets errno to ENOENT at the first time, 

Not really. Don't you have some system call tracing utility to see
what is going on?

The first time some rarely-used function is invoked, it might have
to initialize some persistent state.

This is a common optimization known by names such as "late binding"
or "lazy initialization".

It's possible that the initializations triggered by localtime_r need to
read some files some files related to time zones and whatnot (which
is a good idea to avoid doing if the program doesn't need it).  Maybe that code
searches the filesystem for some things, some of which are not installed, and
so it receives some ENOENT errors.
0
Kaz
3/19/2014 8:13:02 AM
On 03/19/2014 04:13 PM, Kaz Kylheku wrote:
> Not really. Don't you have some system call tracing utility to see
> what is going on?
This is the first time I hear system call tracing utility. Is it useful 
for application developers?

> This is a common optimization known by names such as "late binding"
> or "lazy initialization".
>
> It's possible that the initializations triggered by localtime_r need to
> read some files some files related to time zones and whatnot (which
> is a good idea to avoid doing if the program doesn't need it).  Maybe that code
> searches the filesystem for some things, some of which are not installed, and
> so it receives some ENOENT errors.
>
You are right.
After uploading the file /etc/localtime to the target PowerPC, the 
program does not set errno any more, and the result time has added the 
time zone.
After that, I remove the file /etc/localtime on Ubuntu. And now it also 
shows an ENOENT error after localtime_r, but does not set errno after 
strftime.
Whatever, it makes sense. And I learned what had happened.
Thanks!

0
wy
3/19/2014 12:35:12 PM
On 03/19/2014 04:02 PM, Philip Guenther wrote:
I see.
These functions have done what they should do.
And errno should be checked only when you are sure the system call failed.
It does provide the detail of failure, for this system call, or the 
internals.
Thank you!

0
wy
3/19/2014 12:37:32 PM
On Wed, 2014-03-19, wy wrote:
> On 03/19/2014 04:13 PM, Kaz Kylheku wrote:
>> Not really. Don't you have some system call tracing utility to see
>> what is going on?

> This is the first time I hear system call tracing utility. Is it useful 
> for application developers?

Yes, it is very useful, for many different things.

Since you appear to be on Linux, its name is strace.  Do 'strace ls'
to see an example of what it does.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .
0
Jorgen
3/19/2014 6:51:12 PM
Reply:

Similar Artilces:

""""""""""""""""""""""ADD ME""""""""""""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfo Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... We look forward to build a ve...

"""""""""ADD ME""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfoi Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... ...

Urgent Requirement in """""""""""""NEW YORK""""""""""""""""
Hello Partners, Please find the requirement below. Please send the updated resume along with rate and contact no. REQ#1: Title : Java Developer ( Rating Project) Duration : 6 months Rate : open Location : NY strong java, WebLogic 9.2, Web Services, Oracle REQ#2: Title : Java Developer Duration : 4 months Rate : open Location : NY Strong java, SQL REQ#3: Title : VB.Net Consultant Location : NY Duration : 4 months Rate : open Primarily looking at someone who has Excel, VB.net a...

"/a" is not "/a" ?
Hi everybody, while testing a module today I stumbled on something that I can work around but I don't quite understand. >>> a = "a" >>> b = "a" >>> a == b True >>> a is b True >>> c = "/a" >>> d = "/a" >>> c == d True # all good so far >>> c is d False # eeeeek! Why c and d point to two different objects with an identical string content rather than the same object? Manu Emanuele D'Arrigo wrote: >>>> c = "/a" >>>&...

"out" and "in out"
Hi i found the following explaination: In Ada, "in" parameters are similar to C++ const parameters. They are effectively read-only within the scope of the called subprogram. Ada "in out" parameters have a reliable initial value (that passed in from the calling subprogram) and may be modified within the scope of the called procedure. Ada "out" parameters have no reliable initial value, but are expected to be assigned a value within the called procedure. What does "have no reliable initial value" mean when considering the "out" parameter? By c...

why "::", not "."
Why does the method of modules use a dot, and the constants a double colon? e.g. Math::PI and Math.cos -- Posted via http://www.ruby-forum.com/. On Oct 26, 2010, at 01:48 , Oleg Igor wrote: > Why does the method of modules use a dot, and the constants a double > colon? > e.g. > Math::PI and Math.cos For the same reason why inner-classes/modules use double colon, because = they're constants and that's how you look up via constant namespace. Math::PI and ActiveRecord::Base are the same type of lookup... it is = just that Base is a module and PI is a float....

"or" and "and"
Hi, I'm just getting to discover ruby, but I find it very nice programming language. I just still don't understand how the "or" and "and" in ruby... I was playing with ruby and for example made a def to print Stem and Leaf plot (for those who didn't have a statistics course or slept on it, e.g. http://cnx.org/content/m10157/latest/) Here is the Beta version of it: class Array def n ; self.size ; end def stem_and_leaf(st = 1) # if st != (2 or 5 or 10) then ; st = 1 ; end k = Hash.new(0) self.each {|x| k[x.to_f] += 1 } k = k.sort{|a, b| a[0].to_f <=&g...

about "++" and "--"
why this program snippet display "8,7,7,8,-7,-8" the program is: main() { int i=8; printf("%d\n%d\n%d\n%d\n%d\n%d\n",++i,--i,i++,i--,-i++,-i--); } > why this program snippet display "8,7,7,8,-7,-8" Ask your compiler-vendor because this result is IMHO implementation-defined. Check this out: http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.15 http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.16 Regards, Irina Marudina fxc123@gmail.com wrote: > why this program snippet display "8,7,7,8,-7,-8&q...

"my" and "our"
Hi, while testing a program, I erroneously declared the same variable twice within a block, the first time with "my", the second time with "our": { my $fz = 'VTX_Link'; .... ( around 200 lines of code, all in the same block) our $fz = 'VTX_Linkset'; ... } So the initial contents of the $fz declared with "my" is lost, because "our" creates a lexical alias for the global $fz, thus overwriting the previous "my" declaration. It was my error, no question. But I wonder why Perl doesn't mention this - even with "use s...

"If then; if then;" and "If then; if;"
I have a raw data set which is a hierarchical file: H 321 s. main st P Mary E 21 F P william m 23 M P Susan K 3 F H 324 S. Main St I use the folowing code to read the data to creat one observation per detail(P) record including hearder record(H): data test; infile 'C:\Documents and Settings\retain.txt'; retain Address; input type $1. @; if type='H' then input @3 Address $12.; if type='P' then input @3 Name $10. @13 Age 3. @16 Gender $1.; run; but the output is not what I want: 1 321 s. main H 2 321 s. main P Mary E 21 F 3 321 s...

Urgent Requirement for """""""""""""""INFORMATICA DEVELOPER"""""""""""""
Hello Partners, How are you ? Please find the requirements below. Title: Database/ETL Developer Duration: 6 months Location: NY Exp: 7+ Locals preferred Database/ETL requirements (Mandatory) Candidate must have worked with financial instruments, preferably Mutual Funds but, Equities are also ok. PL/SQL - packages, Stored procs, Functions, Aggregate functions, Pipelined Functions Informatica 8.6 - especially complex mappings, complex maplets, complex workflows, transformations Oracle 10g/11g Unix/Linux shell scripting ...

Urgent need """""""""""INFORMATICA DEVELOPER"""""""""""""
Hello Partners, How are you ? Please find the requirements below. Title: Database/ETL Developer Duration: 6 months Location: NY Exp: 7+ Locals preferred Database/ETL requirements (Mandatory) Candidate must have worked with financial instruments, preferably Mutual Funds but, Equities are also ok. PL/SQL - packages, Stored procs, Functions, Aggregate functions, Pipelined Functions Informatica 8.6 - especially complex mappings, complex maplets, complex workflows, transformations Oracle 10g/11g Unix/Linux shell scripting Database/ETL requirements (Optional) ...

A problem about "[ ]" "( )" "="
I want to read several images saved in a director,and give them to I1,I2 ,I3....,using the following codes: filelist=dir(['c:\MATLAB701\work\...\*.jpg']); for i=1 :length(filelist) I=imread(fullfile('c:\MATLAB701\work\...',filelist(i).name)); end; but failed. Then I used I(i)=imread... ,still failed. How could I do? "John" <mailofww@126.com> wrote in message news:ef19e12.-1@webx.raydaftYaTP... >I want to read several images saved in a director,and give them to > I1,I2 ,I3....,using the following codes: > filelist=dir(['c:\MATLAB701\work\.....

Does it need a ";" at the very after of "if" and "for"
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if statement? marsarden said: > write code like: > > int main(void) > { > int a=10; > if(a<20) > {} > } > > Compiler ok on dev-cpp . don't we have to add a ";" after if > statement? The syntax for 'if' is: if(expression) statement There is no semicolon after the ) but before the statement. The statement is either a normal statement (which can be empty), ending in a semicolon:- if(expr) ...

Web resources about - function "strftime" produce "No such file or directory" error - comp.unix.programmer

Resources last updated: 1/27/2016 3:35:13 AM