...
In the following noncompliant code, unsafe characters are used as part of a file name.
Code Block | ||
---|---|---|
| ||
#include <fcntl.h> #include <sys/stat.h> int main(void) { char *file_name = "»£???«"; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; int fd = open(file_name, O_CREAT | O_EXCL | O_WRONLY, mode); if (fd == -1) { /* Handle Error */ } }File f = new File("A\uD8AB"); OutputStream out = new FileOutputStream(f); |
An implementation is free to define its own mapping of the non-"safe" characters. For example, when tested on a Red Hat an Ubuntu Linux distribution, this noncompliant code example resulted in the following file name:
Code Block |
---|
???A??? |
Compliant Solution: File Name
Use a descriptive file name, containing only the subset of ASCII previously described.
Code Block | ||
---|---|---|
| ||
#include <fcntl.h> #include <sys/stat.h> int main(void) { char *file_name = File f = new File("name.ext"); mode_t modeOutputStream out = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; int fd = open(file_name, O_CREAT | O_EXCL | O_WRONLY, mode); if (fd == -1) { /* Handle Error */ } }new FileOutputStream(f); |
Noncompliant Code Example (File Name)
...