1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2013 - Scilab Enterprises - Cedric Delamarre
4 *
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
6 *
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
13 *
14 */
15 /*--------------------------------------------------------------------------*/
16 #include <string.h> /* strlen */
17 #include "filemanager.hxx"
18 #include "file.hxx"
19
20 extern "C"
21 {
22 #include "getfileinfo.h"
23 #include "charEncoding.h"
24 #include "sci_malloc.h"
25 }
26 /*--------------------------------------------------------------------------*/
C2F(getfileinfo)27 void C2F(getfileinfo)(int *fd, FILE *fa, int *swap2, int *type, int *mode, char *filename, int *lf, int *ierr)
28 {
29 const wchar_t *filenamefromfd = NULL;
30 if (*fd < 0)
31 {
32 *ierr = 1;
33 return;
34 }
35
36 types::File* pFile = FileManager::getFile(*fd);
37
38 if (*fd >= FileManager::getFileMaxID() || pFile == NULL || pFile->getFileType() == 0)
39 {
40 *ierr = 2;
41 return;
42 }
43
44 *swap2 = pFile->getFileSwap();
45 *type = pFile->getFileType();
46 *mode = pFile->getFileModeAsInt();
47 filenamefromfd = pFile->getFilename().c_str();
48 if (filenamefromfd)
49 {
50 char* pstFileName = wide_string_to_UTF8(filenamefromfd);
51 strcpy(filename, pstFileName);
52 FREE(pstFileName);
53 }
54 else
55 {
56 strcpy(filename, "");
57 }
58
59 *lf = (int)strlen(filename);
60 *ierr = 0;
61 }
62 /*--------------------------------------------------------------------------*/
63