inquire.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /* Copyright (C) 2002-2015 Free Software Foundation, Inc.
  2. Contributed by Andy Vaught
  3. This file is part of the GNU Fortran runtime library (libgfortran).
  4. Libgfortran is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. Libgfortran is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* Implement the non-IOLENGTH variant of the INQUIRY statement */
  20. #include "io.h"
  21. #include "unix.h"
  22. #include <string.h>
  23. static const char yes[] = "YES", no[] = "NO", undefined[] = "UNDEFINED";
  24. /* inquire_via_unit()-- Inquiry via unit number. The unit might not exist. */
  25. static void
  26. inquire_via_unit (st_parameter_inquire *iqp, gfc_unit * u)
  27. {
  28. const char *p;
  29. GFC_INTEGER_4 cf = iqp->common.flags;
  30. if (iqp->common.unit == GFC_INTERNAL_UNIT)
  31. generate_error (&iqp->common, LIBERROR_INQUIRE_INTERNAL_UNIT, NULL);
  32. if ((cf & IOPARM_INQUIRE_HAS_EXIST) != 0)
  33. *iqp->exist = (u != NULL) || (iqp->common.unit >= 0);
  34. if ((cf & IOPARM_INQUIRE_HAS_OPENED) != 0)
  35. *iqp->opened = (u != NULL);
  36. if ((cf & IOPARM_INQUIRE_HAS_NUMBER) != 0)
  37. *iqp->number = (u != NULL) ? u->unit_number : -1;
  38. if ((cf & IOPARM_INQUIRE_HAS_NAMED) != 0)
  39. *iqp->named = (u != NULL && u->flags.status != STATUS_SCRATCH);
  40. if ((cf & IOPARM_INQUIRE_HAS_NAME) != 0
  41. && u != NULL && u->flags.status != STATUS_SCRATCH)
  42. {
  43. #if defined(HAVE_TTYNAME_R) || defined(HAVE_TTYNAME)
  44. if (u->unit_number == options.stdin_unit
  45. || u->unit_number == options.stdout_unit
  46. || u->unit_number == options.stderr_unit)
  47. {
  48. int err = stream_ttyname (u->s, iqp->name, iqp->name_len);
  49. if (err == 0)
  50. {
  51. gfc_charlen_type tmplen = strlen (iqp->name);
  52. if (iqp->name_len > tmplen)
  53. memset (&iqp->name[tmplen], ' ', iqp->name_len - tmplen);
  54. }
  55. else /* If ttyname does not work, go with the default. */
  56. cf_strcpy (iqp->name, iqp->name_len, u->filename);
  57. }
  58. else
  59. cf_strcpy (iqp->name, iqp->name_len, u->filename);
  60. #elif defined __MINGW32__
  61. if (u->unit_number == options.stdin_unit)
  62. fstrcpy (iqp->name, iqp->name_len, "CONIN$", sizeof("CONIN$"));
  63. else if (u->unit_number == options.stdout_unit)
  64. fstrcpy (iqp->name, iqp->name_len, "CONOUT$", sizeof("CONOUT$"));
  65. else if (u->unit_number == options.stderr_unit)
  66. fstrcpy (iqp->name, iqp->name_len, "CONERR$", sizeof("CONERR$"));
  67. else
  68. cf_strcpy (iqp->name, iqp->name_len, u->filename);
  69. #else
  70. cf_strcpy (iqp->name, iqp->name_len, u->filename);
  71. #endif
  72. }
  73. if ((cf & IOPARM_INQUIRE_HAS_ACCESS) != 0)
  74. {
  75. if (u == NULL)
  76. p = undefined;
  77. else
  78. switch (u->flags.access)
  79. {
  80. case ACCESS_SEQUENTIAL:
  81. p = "SEQUENTIAL";
  82. break;
  83. case ACCESS_DIRECT:
  84. p = "DIRECT";
  85. break;
  86. case ACCESS_STREAM:
  87. p = "STREAM";
  88. break;
  89. default:
  90. internal_error (&iqp->common, "inquire_via_unit(): Bad access");
  91. }
  92. cf_strcpy (iqp->access, iqp->access_len, p);
  93. }
  94. if ((cf & IOPARM_INQUIRE_HAS_SEQUENTIAL) != 0)
  95. {
  96. if (u == NULL)
  97. p = inquire_sequential (NULL, 0);
  98. else
  99. switch (u->flags.access)
  100. {
  101. case ACCESS_DIRECT:
  102. case ACCESS_STREAM:
  103. p = no;
  104. break;
  105. case ACCESS_SEQUENTIAL:
  106. p = yes;
  107. break;
  108. default:
  109. internal_error (&iqp->common, "inquire_via_unit(): Bad access");
  110. }
  111. cf_strcpy (iqp->sequential, iqp->sequential_len, p);
  112. }
  113. if ((cf & IOPARM_INQUIRE_HAS_DIRECT) != 0)
  114. {
  115. if (u == NULL)
  116. p = inquire_direct (NULL, 0);
  117. else
  118. switch (u->flags.access)
  119. {
  120. case ACCESS_SEQUENTIAL:
  121. case ACCESS_STREAM:
  122. p = no;
  123. break;
  124. case ACCESS_DIRECT:
  125. p = yes;
  126. break;
  127. default:
  128. internal_error (&iqp->common, "inquire_via_unit(): Bad access");
  129. }
  130. cf_strcpy (iqp->direct, iqp->direct_len, p);
  131. }
  132. if ((cf & IOPARM_INQUIRE_HAS_FORM) != 0)
  133. {
  134. if (u == NULL)
  135. p = undefined;
  136. else
  137. switch (u->flags.form)
  138. {
  139. case FORM_FORMATTED:
  140. p = "FORMATTED";
  141. break;
  142. case FORM_UNFORMATTED:
  143. p = "UNFORMATTED";
  144. break;
  145. default:
  146. internal_error (&iqp->common, "inquire_via_unit(): Bad form");
  147. }
  148. cf_strcpy (iqp->form, iqp->form_len, p);
  149. }
  150. if ((cf & IOPARM_INQUIRE_HAS_FORMATTED) != 0)
  151. {
  152. if (u == NULL)
  153. p = inquire_formatted (NULL, 0);
  154. else
  155. switch (u->flags.form)
  156. {
  157. case FORM_FORMATTED:
  158. p = yes;
  159. break;
  160. case FORM_UNFORMATTED:
  161. p = no;
  162. break;
  163. default:
  164. internal_error (&iqp->common, "inquire_via_unit(): Bad form");
  165. }
  166. cf_strcpy (iqp->formatted, iqp->formatted_len, p);
  167. }
  168. if ((cf & IOPARM_INQUIRE_HAS_UNFORMATTED) != 0)
  169. {
  170. if (u == NULL)
  171. p = inquire_unformatted (NULL, 0);
  172. else
  173. switch (u->flags.form)
  174. {
  175. case FORM_FORMATTED:
  176. p = no;
  177. break;
  178. case FORM_UNFORMATTED:
  179. p = yes;
  180. break;
  181. default:
  182. internal_error (&iqp->common, "inquire_via_unit(): Bad form");
  183. }
  184. cf_strcpy (iqp->unformatted, iqp->unformatted_len, p);
  185. }
  186. if ((cf & IOPARM_INQUIRE_HAS_RECL_OUT) != 0)
  187. *iqp->recl_out = (u != NULL) ? u->recl : 0;
  188. if ((cf & IOPARM_INQUIRE_HAS_STRM_POS_OUT) != 0)
  189. *iqp->strm_pos_out = (u != NULL) ? u->strm_pos : 0;
  190. if ((cf & IOPARM_INQUIRE_HAS_NEXTREC) != 0)
  191. {
  192. /* This only makes sense in the context of DIRECT access. */
  193. if (u != NULL && u->flags.access == ACCESS_DIRECT)
  194. *iqp->nextrec = u->last_record + 1;
  195. else
  196. *iqp->nextrec = 0;
  197. }
  198. if ((cf & IOPARM_INQUIRE_HAS_BLANK) != 0)
  199. {
  200. if (u == NULL || u->flags.form != FORM_FORMATTED)
  201. p = undefined;
  202. else
  203. switch (u->flags.blank)
  204. {
  205. case BLANK_NULL:
  206. p = "NULL";
  207. break;
  208. case BLANK_ZERO:
  209. p = "ZERO";
  210. break;
  211. default:
  212. internal_error (&iqp->common, "inquire_via_unit(): Bad blank");
  213. }
  214. cf_strcpy (iqp->blank, iqp->blank_len, p);
  215. }
  216. if ((cf & IOPARM_INQUIRE_HAS_PAD) != 0)
  217. {
  218. if (u == NULL || u->flags.form != FORM_FORMATTED)
  219. p = undefined;
  220. else
  221. switch (u->flags.pad)
  222. {
  223. case PAD_YES:
  224. p = yes;
  225. break;
  226. case PAD_NO:
  227. p = no;
  228. break;
  229. default:
  230. internal_error (&iqp->common, "inquire_via_unit(): Bad pad");
  231. }
  232. cf_strcpy (iqp->pad, iqp->pad_len, p);
  233. }
  234. if (cf & IOPARM_INQUIRE_HAS_FLAGS2)
  235. {
  236. GFC_INTEGER_4 cf2 = iqp->flags2;
  237. if ((cf2 & IOPARM_INQUIRE_HAS_PENDING) != 0)
  238. *iqp->pending = 0;
  239. if ((cf2 & IOPARM_INQUIRE_HAS_ID) != 0)
  240. *iqp->id = 0;
  241. if ((cf2 & IOPARM_INQUIRE_HAS_ENCODING) != 0)
  242. {
  243. if (u == NULL || u->flags.form != FORM_FORMATTED)
  244. p = undefined;
  245. else
  246. switch (u->flags.encoding)
  247. {
  248. case ENCODING_DEFAULT:
  249. p = "UNKNOWN";
  250. break;
  251. case ENCODING_UTF8:
  252. p = "UTF-8";
  253. break;
  254. default:
  255. internal_error (&iqp->common, "inquire_via_unit(): Bad encoding");
  256. }
  257. cf_strcpy (iqp->encoding, iqp->encoding_len, p);
  258. }
  259. if ((cf2 & IOPARM_INQUIRE_HAS_DECIMAL) != 0)
  260. {
  261. if (u == NULL || u->flags.form != FORM_FORMATTED)
  262. p = undefined;
  263. else
  264. switch (u->flags.decimal)
  265. {
  266. case DECIMAL_POINT:
  267. p = "POINT";
  268. break;
  269. case DECIMAL_COMMA:
  270. p = "COMMA";
  271. break;
  272. default:
  273. internal_error (&iqp->common, "inquire_via_unit(): Bad comma");
  274. }
  275. cf_strcpy (iqp->decimal, iqp->decimal_len, p);
  276. }
  277. if ((cf2 & IOPARM_INQUIRE_HAS_ASYNCHRONOUS) != 0)
  278. {
  279. if (u == NULL)
  280. p = undefined;
  281. else
  282. switch (u->flags.async)
  283. {
  284. case ASYNC_YES:
  285. p = yes;
  286. break;
  287. case ASYNC_NO:
  288. p = no;
  289. break;
  290. default:
  291. internal_error (&iqp->common, "inquire_via_unit(): Bad async");
  292. }
  293. cf_strcpy (iqp->asynchronous, iqp->asynchronous_len, p);
  294. }
  295. if ((cf2 & IOPARM_INQUIRE_HAS_SIGN) != 0)
  296. {
  297. if (u == NULL)
  298. p = undefined;
  299. else
  300. switch (u->flags.sign)
  301. {
  302. case SIGN_PROCDEFINED:
  303. p = "PROCESSOR_DEFINED";
  304. break;
  305. case SIGN_SUPPRESS:
  306. p = "SUPPRESS";
  307. break;
  308. case SIGN_PLUS:
  309. p = "PLUS";
  310. break;
  311. default:
  312. internal_error (&iqp->common, "inquire_via_unit(): Bad sign");
  313. }
  314. cf_strcpy (iqp->sign, iqp->sign_len, p);
  315. }
  316. if ((cf2 & IOPARM_INQUIRE_HAS_ROUND) != 0)
  317. {
  318. if (u == NULL)
  319. p = undefined;
  320. else
  321. switch (u->flags.round)
  322. {
  323. case ROUND_UP:
  324. p = "UP";
  325. break;
  326. case ROUND_DOWN:
  327. p = "DOWN";
  328. break;
  329. case ROUND_ZERO:
  330. p = "ZERO";
  331. break;
  332. case ROUND_NEAREST:
  333. p = "NEAREST";
  334. break;
  335. case ROUND_COMPATIBLE:
  336. p = "COMPATIBLE";
  337. break;
  338. case ROUND_PROCDEFINED:
  339. p = "PROCESSOR_DEFINED";
  340. break;
  341. default:
  342. internal_error (&iqp->common, "inquire_via_unit(): Bad round");
  343. }
  344. cf_strcpy (iqp->round, iqp->round_len, p);
  345. }
  346. if ((cf2 & IOPARM_INQUIRE_HAS_SIZE) != 0)
  347. {
  348. if (u == NULL)
  349. *iqp->size = -1;
  350. else
  351. {
  352. sflush (u->s);
  353. *iqp->size = ssize (u->s);
  354. }
  355. }
  356. if ((cf2 & IOPARM_INQUIRE_HAS_IQSTREAM) != 0)
  357. {
  358. if (u == NULL)
  359. p = "UNKNOWN";
  360. else
  361. switch (u->flags.access)
  362. {
  363. case ACCESS_SEQUENTIAL:
  364. case ACCESS_DIRECT:
  365. p = no;
  366. break;
  367. case ACCESS_STREAM:
  368. p = yes;
  369. break;
  370. default:
  371. internal_error (&iqp->common, "inquire_via_unit(): Bad pad");
  372. }
  373. cf_strcpy (iqp->iqstream, iqp->iqstream_len, p);
  374. }
  375. }
  376. if ((cf & IOPARM_INQUIRE_HAS_POSITION) != 0)
  377. {
  378. if (u == NULL || u->flags.access == ACCESS_DIRECT)
  379. p = undefined;
  380. else
  381. {
  382. /* If the position is unspecified, check if we can figure
  383. out whether it's at the beginning or end. */
  384. if (u->flags.position == POSITION_UNSPECIFIED)
  385. {
  386. gfc_offset cur = stell (u->s);
  387. if (cur == 0)
  388. u->flags.position = POSITION_REWIND;
  389. else if (cur != -1 && (ssize (u->s) == cur))
  390. u->flags.position = POSITION_APPEND;
  391. }
  392. switch (u->flags.position)
  393. {
  394. case POSITION_REWIND:
  395. p = "REWIND";
  396. break;
  397. case POSITION_APPEND:
  398. p = "APPEND";
  399. break;
  400. case POSITION_ASIS:
  401. p = "ASIS";
  402. break;
  403. default:
  404. /* If the position has changed and is not rewind or
  405. append, it must be set to a processor-dependent
  406. value. */
  407. p = "UNSPECIFIED";
  408. break;
  409. }
  410. }
  411. cf_strcpy (iqp->position, iqp->position_len, p);
  412. }
  413. if ((cf & IOPARM_INQUIRE_HAS_ACTION) != 0)
  414. {
  415. if (u == NULL)
  416. p = undefined;
  417. else
  418. switch (u->flags.action)
  419. {
  420. case ACTION_READ:
  421. p = "READ";
  422. break;
  423. case ACTION_WRITE:
  424. p = "WRITE";
  425. break;
  426. case ACTION_READWRITE:
  427. p = "READWRITE";
  428. break;
  429. default:
  430. internal_error (&iqp->common, "inquire_via_unit(): Bad action");
  431. }
  432. cf_strcpy (iqp->action, iqp->action_len, p);
  433. }
  434. if ((cf & IOPARM_INQUIRE_HAS_READ) != 0)
  435. {
  436. p = (!u || u->flags.action == ACTION_WRITE) ? no : yes;
  437. cf_strcpy (iqp->read, iqp->read_len, p);
  438. }
  439. if ((cf & IOPARM_INQUIRE_HAS_WRITE) != 0)
  440. {
  441. p = (!u || u->flags.action == ACTION_READ) ? no : yes;
  442. cf_strcpy (iqp->write, iqp->write_len, p);
  443. }
  444. if ((cf & IOPARM_INQUIRE_HAS_READWRITE) != 0)
  445. {
  446. p = (!u || u->flags.action != ACTION_READWRITE) ? no : yes;
  447. cf_strcpy (iqp->readwrite, iqp->readwrite_len, p);
  448. }
  449. if ((cf & IOPARM_INQUIRE_HAS_DELIM) != 0)
  450. {
  451. if (u == NULL || u->flags.form != FORM_FORMATTED)
  452. p = undefined;
  453. else
  454. switch (u->flags.delim)
  455. {
  456. case DELIM_NONE:
  457. case DELIM_UNSPECIFIED:
  458. p = "NONE";
  459. break;
  460. case DELIM_QUOTE:
  461. p = "QUOTE";
  462. break;
  463. case DELIM_APOSTROPHE:
  464. p = "APOSTROPHE";
  465. break;
  466. default:
  467. internal_error (&iqp->common, "inquire_via_unit(): Bad delim");
  468. }
  469. cf_strcpy (iqp->delim, iqp->delim_len, p);
  470. }
  471. if ((cf & IOPARM_INQUIRE_HAS_PAD) != 0)
  472. {
  473. if (u == NULL || u->flags.form != FORM_FORMATTED)
  474. p = undefined;
  475. else
  476. switch (u->flags.pad)
  477. {
  478. case PAD_NO:
  479. p = no;
  480. break;
  481. case PAD_YES:
  482. p = yes;
  483. break;
  484. default:
  485. internal_error (&iqp->common, "inquire_via_unit(): Bad pad");
  486. }
  487. cf_strcpy (iqp->pad, iqp->pad_len, p);
  488. }
  489. if ((cf & IOPARM_INQUIRE_HAS_CONVERT) != 0)
  490. {
  491. if (u == NULL)
  492. p = undefined;
  493. else
  494. switch (u->flags.convert)
  495. {
  496. /* big_endian is 0 for little-endian, 1 for big-endian. */
  497. case GFC_CONVERT_NATIVE:
  498. p = big_endian ? "BIG_ENDIAN" : "LITTLE_ENDIAN";
  499. break;
  500. case GFC_CONVERT_SWAP:
  501. p = big_endian ? "LITTLE_ENDIAN" : "BIG_ENDIAN";
  502. break;
  503. default:
  504. internal_error (&iqp->common, "inquire_via_unit(): Bad convert");
  505. }
  506. cf_strcpy (iqp->convert, iqp->convert_len, p);
  507. }
  508. }
  509. /* inquire_via_filename()-- Inquiry via filename. This subroutine is
  510. * only used if the filename is *not* connected to a unit number. */
  511. static void
  512. inquire_via_filename (st_parameter_inquire *iqp)
  513. {
  514. const char *p;
  515. GFC_INTEGER_4 cf = iqp->common.flags;
  516. if ((cf & IOPARM_INQUIRE_HAS_EXIST) != 0)
  517. *iqp->exist = file_exists (iqp->file, iqp->file_len);
  518. if ((cf & IOPARM_INQUIRE_HAS_OPENED) != 0)
  519. *iqp->opened = 0;
  520. if ((cf & IOPARM_INQUIRE_HAS_NUMBER) != 0)
  521. *iqp->number = -1;
  522. if ((cf & IOPARM_INQUIRE_HAS_NAMED) != 0)
  523. *iqp->named = 1;
  524. if ((cf & IOPARM_INQUIRE_HAS_NAME) != 0)
  525. fstrcpy (iqp->name, iqp->name_len, iqp->file, iqp->file_len);
  526. if ((cf & IOPARM_INQUIRE_HAS_ACCESS) != 0)
  527. cf_strcpy (iqp->access, iqp->access_len, undefined);
  528. if ((cf & IOPARM_INQUIRE_HAS_SEQUENTIAL) != 0)
  529. {
  530. p = "UNKNOWN";
  531. cf_strcpy (iqp->sequential, iqp->sequential_len, p);
  532. }
  533. if ((cf & IOPARM_INQUIRE_HAS_DIRECT) != 0)
  534. {
  535. p = "UNKNOWN";
  536. cf_strcpy (iqp->direct, iqp->direct_len, p);
  537. }
  538. if ((cf & IOPARM_INQUIRE_HAS_FORM) != 0)
  539. cf_strcpy (iqp->form, iqp->form_len, undefined);
  540. if ((cf & IOPARM_INQUIRE_HAS_FORMATTED) != 0)
  541. {
  542. p = "UNKNOWN";
  543. cf_strcpy (iqp->formatted, iqp->formatted_len, p);
  544. }
  545. if ((cf & IOPARM_INQUIRE_HAS_UNFORMATTED) != 0)
  546. {
  547. p = "UNKNOWN";
  548. cf_strcpy (iqp->unformatted, iqp->unformatted_len, p);
  549. }
  550. if ((cf & IOPARM_INQUIRE_HAS_RECL_OUT) != 0)
  551. *iqp->recl_out = 0;
  552. if ((cf & IOPARM_INQUIRE_HAS_NEXTREC) != 0)
  553. *iqp->nextrec = 0;
  554. if ((cf & IOPARM_INQUIRE_HAS_BLANK) != 0)
  555. cf_strcpy (iqp->blank, iqp->blank_len, undefined);
  556. if ((cf & IOPARM_INQUIRE_HAS_PAD) != 0)
  557. cf_strcpy (iqp->pad, iqp->pad_len, undefined);
  558. if (cf & IOPARM_INQUIRE_HAS_FLAGS2)
  559. {
  560. GFC_INTEGER_4 cf2 = iqp->flags2;
  561. if ((cf2 & IOPARM_INQUIRE_HAS_ENCODING) != 0)
  562. cf_strcpy (iqp->encoding, iqp->encoding_len, undefined);
  563. if ((cf2 & IOPARM_INQUIRE_HAS_DELIM) != 0)
  564. cf_strcpy (iqp->delim, iqp->delim_len, undefined);
  565. if ((cf2 & IOPARM_INQUIRE_HAS_DECIMAL) != 0)
  566. cf_strcpy (iqp->decimal, iqp->decimal_len, undefined);
  567. if ((cf2 & IOPARM_INQUIRE_HAS_DELIM) != 0)
  568. cf_strcpy (iqp->delim, iqp->delim_len, undefined);
  569. if ((cf2 & IOPARM_INQUIRE_HAS_PAD) != 0)
  570. cf_strcpy (iqp->pad, iqp->pad_len, undefined);
  571. if ((cf2 & IOPARM_INQUIRE_HAS_ENCODING) != 0)
  572. cf_strcpy (iqp->encoding, iqp->encoding_len, undefined);
  573. if ((cf2 & IOPARM_INQUIRE_HAS_SIZE) != 0)
  574. *iqp->size = file_size (iqp->file, iqp->file_len);
  575. if ((cf2 & IOPARM_INQUIRE_HAS_IQSTREAM) != 0)
  576. cf_strcpy (iqp->iqstream, iqp->iqstream_len, "UNKNOWN");
  577. }
  578. if ((cf & IOPARM_INQUIRE_HAS_POSITION) != 0)
  579. cf_strcpy (iqp->position, iqp->position_len, undefined);
  580. if ((cf & IOPARM_INQUIRE_HAS_ACCESS) != 0)
  581. cf_strcpy (iqp->access, iqp->access_len, undefined);
  582. if ((cf & IOPARM_INQUIRE_HAS_READ) != 0)
  583. {
  584. p = inquire_read (iqp->file, iqp->file_len);
  585. cf_strcpy (iqp->read, iqp->read_len, p);
  586. }
  587. if ((cf & IOPARM_INQUIRE_HAS_WRITE) != 0)
  588. {
  589. p = inquire_write (iqp->file, iqp->file_len);
  590. cf_strcpy (iqp->write, iqp->write_len, p);
  591. }
  592. if ((cf & IOPARM_INQUIRE_HAS_READWRITE) != 0)
  593. {
  594. p = inquire_read (iqp->file, iqp->file_len);
  595. cf_strcpy (iqp->readwrite, iqp->readwrite_len, p);
  596. }
  597. }
  598. /* Library entry point for the INQUIRE statement (non-IOLENGTH
  599. form). */
  600. extern void st_inquire (st_parameter_inquire *);
  601. export_proto(st_inquire);
  602. void
  603. st_inquire (st_parameter_inquire *iqp)
  604. {
  605. gfc_unit *u;
  606. library_start (&iqp->common);
  607. if ((iqp->common.flags & IOPARM_INQUIRE_HAS_FILE) == 0)
  608. {
  609. u = find_unit (iqp->common.unit);
  610. inquire_via_unit (iqp, u);
  611. }
  612. else
  613. {
  614. u = find_file (iqp->file, iqp->file_len);
  615. if (u == NULL)
  616. inquire_via_filename (iqp);
  617. else
  618. inquire_via_unit (iqp, u);
  619. }
  620. if (u != NULL)
  621. unlock_unit (u);
  622. library_end ();
  623. }