Hi Mohammad.
Thanks for the patch. See some comments below. > Signed-off-by: Mohammad-Reza Nabipoor <[email protected]> > > gcc/ChangeLog > > * algol68/a68-imports.cc (a68_find_export_data): Implement > reading from module's .m68 file if available. Please use gcc/algol68/Changelog, and adjust relative paths accordingly. > --- > gcc/algol68/a68-imports.cc | 50 ++++++++++++++++++++++++++++++++++---- > 1 file changed, 45 insertions(+), 5 deletions(-) > > diff --git a/gcc/algol68/a68-imports.cc b/gcc/algol68/a68-imports.cc > index 9cd6615b7a4..4a92c197610 100644 > --- a/gcc/algol68/a68-imports.cc > +++ b/gcc/algol68/a68-imports.cc > @@ -169,15 +169,56 @@ a68_find_export_data (const std::string &filename, int > fd, size_t *psize) > } > > char buf[A68_EXPORT_MAGIC_LEN]; > - ssize_t c = ::read(fd, buf, A68_EXPORT_MAGIC_LEN); > + ssize_t c = read (fd, buf, A68_EXPORT_MAGIC_LEN); > if (c < A68_EXPORT_MAGIC_LEN) > return NULL; > > /* Check for a file containing nothing but Algol 68 export data. */ > - if (buf[0] == '\x0a' && buf[1] == '\xad') > + if (buf[0] == '\x0a' && buf[1] == '\x68') > { > - /* XXX read whole file. */ > - return exports; > + /* read whole file. */ > + > + char *buf; > + off_t len; > + ssize_t nread; > + > + len = lseek (fd, 0, SEEK_END); > + if (len < 0) > + { > + a68_error (NO_NODE, "lseek Z failed", filename.c_str ()); > + return NULL; > + } > + if (lseek (fd, 0, SEEK_SET) < 0) > + { > + a68_error (NO_NODE, "lseek Z failed", filename.c_str ()); > + return NULL; > + } > + > + buf = XNEWVEC (char, len); > + if (buf == NULL) > + { > + a68_error (NO_NODE, > + "memory allocation failed while reading export data"); > + return NULL; > + } > + > + nread = read (fd, buf, len); > + if (nread < 0) > + { > + free (buf); > + a68_error (NO_NODE, "read failed while reading export data"); > + return NULL; > + } > + > + if (nread < len) > + { > + free (buf); > + a68_error (NO_NODE, "short read while reading export data"); > + return NULL; > + } > + > + *psize = len; > + return buf; I am currently working in implementing -fmodules-map-file=<filename> and, along with the scanner, that is another place where to read the full contents of a file in a buffer. So I am factoring out a function for that, and I suggest to use it for this as well. > } > > #if 0 > @@ -187,7 +228,6 @@ a68_find_export_data (const std::string &filename, int > fd, size_t *psize) > #endif > > return NULL; > - > } > > /* Given *PFILENAME, where *PFILENAME does not exist, try various suffixes. > If
