[PATCH] Add writeFileWithSystemEncoding to LibLLVMSupport

Rafael EspĂ­ndola rafael.espindola at gmail.com
Mon Aug 25 11:36:53 PDT 2014


> ================
> Comment at: include/llvm/Support/Program.h:146
> @@ +145,3 @@
> +  /// \returns true if successful, otherwise \p ErrMsg is filled accordingly.
> +  std::error_code writeFileWithEncoding(const char *FileName, StringRef contents,
> +                                        std::string *ErrMsg = nullptr,
> ----------------
> Please don't pass in the ErrMsg string. The caller can use EC.message() method. That is an old API design we try to avoid. I see it is used because raw_fd_osstream was never updated to avoid it :-(
>
> Suggestion: pass in a file descriptor. That way you can use a raw_fd_ostream with a saner interface and we don't spread the use of std::string pointers for error messages to other APIs.
>
> Another option: keep the filename, but use openFileForWrite + the fd raw_fd_ostream constructor.

I just updated the raw_fd_osstream constructor signature in 216393.
This should let you keep using raw_fd_osstream while avoiding the
"const char *" and the std::string &.

Cheers,
Rafael



More information about the llvm-commits mailing list