Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

Compiling microsoft code. Where to get fopen_s?

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
5 posts • Page 1 of 1
Author
Message
tkzv
Tux's lil' helper
Tux's lil' helper
Posts: 121
Joined: Fri Aug 22, 2014 6:56 pm

Compiling microsoft code. Where to get fopen_s?

  • Quote

Post by tkzv » Sat Apr 23, 2016 9:54 pm

I am trying to compile a console program I downloaded from MSDN: http://xbox.create.msdn.com/en-US/sample/xnb_format

There seem to be no references to any external libraries beside a single header file:

Code: Select all

#pragma once

#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>

#include <algorithm>
#include <exception>
#include <type_traits>
#include <string>
#include <vector>

using namespace std;
What libraries and headers do I need to specify?

GCC recognizes the code as C++11 and suggests the switch -std=c++11 . When I set it, it still doesn't find the declaration for fopen_s. Other sites suggest specifying -std=c11, but GCC allows it only for C or ObjC.

What do I need to build it?

Alternatively, how else can I unpack *.XNB files from XNA Game Studio?

sys-devel/gcc versions 4.9.3 and 5.3.0.
Top
Akkara
Bodhisattva
Bodhisattva
User avatar
Posts: 6702
Joined: Tue Mar 28, 2006 12:27 pm
Location: &akkara

  • Quote

Post by Akkara » Sat Apr 23, 2016 11:06 pm

First time I've heard of that one. Seems to be a Microsoftism. This link and the followup comments seem to explain the situation clearly: http://stackoverflow.com/questions/2575 ... g-to-files

It doesn't seem it would be too difficult to define your own as a static inline that calls fopen, checks for errors, and returns the results expected of fopen_s. Put it in the .h file and compile away. I'd offer to take a stab at providing a sample, but instead of risking advising in error, I'll wait see if steveL visits and offers his signature POSIX-ly correct advice right off the top of his head :)
Many think that Dilbert is a comic. Unfortunately it is a documentary.
Top
tkzv
Tux's lil' helper
Tux's lil' helper
Posts: 121
Joined: Fri Aug 22, 2014 6:56 pm

  • Quote

Post by tkzv » Sun Apr 24, 2016 12:00 am

Akkara wrote:First time I've heard of that one. Seems to be a Microsoftism. This link and the followup comments seem to explain the situation clearly: http://stackoverflow.com/questions/2575 ... g-to-files

It doesn't seem it would be too difficult to define your own as a static inline that calls fopen, checks for errors, and returns the results expected of fopen_s. Put it in the .h file and compile away. I'd offer to take a stab at providing a sample, but instead of risking advising in error, I'll wait see if steveL visits and offers his signature POSIX-ly correct advice right off the top of his head :)


If you think stackoverflow.com is a reliable source of information, here's another page: http://stackoverflow.com/questions/1513 ... e-about-it

1. fopen_s is defined in the 2011 standard:
http://en.cppreference.com/w/c/io/fopen
http://www.open-std.org/jtc1/sc22/wg14/ ... /n1570.pdf
And it is available in GCC for *.c files.

2. There are examples of simple hacks that use macros to give fopen_s, but kind of defeat its purpose being as unsafe as fopen.

What I'm asking about, is the way to do it right. Maybe define some GCC-specific variable. Maybe use some MinGW header file. Maybe rebuild some library. There will be other troubles like this one, I'm searching for the universal solution.
Top
Genone
Retired Dev
Retired Dev
User avatar
Posts: 9656
Joined: Fri Mar 14, 2003 6:02 pm
Location: beyond the rim

  • Quote

Post by Genone » Mon Apr 25, 2016 9:10 am

Quick research doesn't give any hints that gcc (or rather: glibc) implements fopen_s at all (it is only an optional part of C11). And assuming they do, the spec says:
As all bounds-checked functions, fopen_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including <stdio.h>.
MS has a long history of making their own special _s versions of standard (string) functions for "security" reasons, so this is not exactly a new problem.

EDIT: You'll have to live with one of the usual hacks: https://gcc.gnu.org/wiki/C11Status / https://sourceware.org/ml/libc-alpha/20 ... 00297.html
Top
tkzv
Tux's lil' helper
Tux's lil' helper
Posts: 121
Joined: Fri Aug 22, 2014 6:56 pm

  • Quote

Post by tkzv » Mon Apr 25, 2016 8:56 pm

Genone wrote:EDIT: You'll have to live with one of the usual hacks: https://gcc.gnu.org/wiki/C11Status / https://sourceware.org/ml/libc-alpha/20 ... 00297.html
Thanks.

In other words, instead of compiling readily available Microsoft code, I'm better off rewriting it in a language I actually know.
Top
Post Reply

5 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic