fopen_s

What's that?

Page 1 of 1

7 Replies - 36944 Views - Last Post: 24 May 2009 - 07:50 AM Rate Topic: -----

#1 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,119
  • Joined: 22-February 08

fopen_s

Posted 24 May 2009 - 12:40 AM

I haven't use the i/o operation for a long time now, and suddenly the compiler gives me the warning that I should use fopen_s? Never heard of it, Googled about it and if I'm not wrong it's one of the new things started by Microsoft, am I right?

So, what's so great about fopen_s?
Is This A Good Question/Topic? 0
  • +

Replies To: fopen_s

#2 FaceOfGod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-May 09

Re: fopen_s

Posted 24 May 2009 - 12:51 AM

I think it's something like fprintf(); .
if you're using dev cpp and a c program (because I've met fopen_s too)
try fprintf();
if it doesn't work with it maybe fopen_s is really better , although I think it's a heavy func.
Was This Post Helpful? 0
  • +
  • -

#3 FrozenSnake  Icon User is offline

  • En man från Sverige!

Reputation: 122
  • View blog
  • Posts: 995
  • Joined: 30-July 08

Re: fopen_s

Posted 24 May 2009 - 12:53 AM

http://msdn.microsof...ee9(VS.80).aspx

There are a whole new set of standard library function called whatever_s which are part of the new "secure" standard library.
Was This Post Helpful? 0
  • +
  • -

#4 FaceOfGod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-May 09

Re: fopen_s

Posted 24 May 2009 - 12:58 AM

I still think that fprintf(); and fopen(); e.t.c. are better than that
Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,596
  • Joined: 16-October 07

Re: fopen_s

Posted 24 May 2009 - 02:24 AM

View Postred_4900, on 24 May, 2009 - 01:40 AM, said:

So, what's so great about fopen_s?


Welcome to windows. Breaking hearts and standards wherever is goes. :P

A number of the list _s functions seem to accept an extra max size parameter. They do extra checks against things like buffer overflows. Microsoft has determined that core functions in the C library are part of their security woes. Notably, they recently announced that memcpy is right out.
Was This Post Helpful? 0
  • +
  • -

#6 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,119
  • Joined: 22-February 08

Re: fopen_s

Posted 24 May 2009 - 02:58 AM

Never heard of that before. Thanks for the link baavgai.

It seems like banishing old, unsafe operation like that could only be good for developers. But seeing how this comes from Windows, it makes me think if this is too good to be true. Is there any bad thing about this "secure" standard library? :unsure:
Was This Post Helpful? 0
  • +
  • -

#7 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,596
  • Joined: 16-October 07

Re: fopen_s

Posted 24 May 2009 - 07:11 AM

View Postred_4900, on 24 May, 2009 - 03:58 AM, said:

Is there any bad thing about this "secure" standard library?


Well, it's not a standard library, it's a Windows library.

The only bad thing is that my standard ISO functions now throw compiler warnings. If you are a good programmer and make happy secure Microsoft code, getting that code out of Windows can take a little work.

Some aren't too hard:
#ifndef WIN32
#define localtime_r(tp, ts) *ts = *localtime(tp)



or
#ifdef WIN32
	WSACleanup();
#else
	close(ConnectSocket);
#endif



Some are harder. Also, such includes made for damn ugly code. :P
Was This Post Helpful? 0
  • +
  • -

#8 Elcric  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 101
  • View blog
  • Posts: 453
  • Joined: 02-May 09

Re: fopen_s

Posted 24 May 2009 - 07:50 AM

:D Hello everyone,

This link might help.

http://msdn.microsof...ee9(VS.80).aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1