@@ -100,7 +100,7 @@ pub fn grantpt(fd: &PtyMaster) -> Result<()> {
100
100
/// unlockpt(&master_fd)?;
101
101
///
102
102
/// // Get the name of the slave
103
- /// let slave_name = ptsname(&master_fd)?;
103
+ /// let slave_name = unsafe { ptsname(&master_fd) } ?;
104
104
///
105
105
/// // Try to open the slave
106
106
/// # #[allow(unused_variables)]
@@ -125,20 +125,24 @@ pub fn posix_openpt(flags: fcntl::OFlag) -> Result<PtyMaster> {
125
125
/// [ptsname(3)](http://man7.org/linux/man-pages/man3/ptsname.3.html))
126
126
///
127
127
/// `ptsname()` returns the name of the slave pseudoterminal device corresponding to the master
128
- /// referred to by `fd`. Note that this function is *not* threadsafe. For that see `ptsname_r()`.
128
+ /// referred to by `fd`.
129
129
///
130
130
/// This value is useful for opening the slave pty once the master has already been opened with
131
131
/// `posix_openpt()`.
132
+ ///
133
+ /// On some platforms, `ptsname()` mutates global variables and is *not* threadsafe.
134
+ /// Mutating global variables is always considered `unsafe` by Rust and this
135
+ /// function is marked as `unsafe` to reflect that.
136
+ ///
137
+ /// For a threadsafe and non-`unsafe` alternative on Linux, see `ptsname_r()`.
132
138
#[ inline]
133
- pub fn ptsname ( fd : & PtyMaster ) -> Result < String > {
134
- let name_ptr = unsafe { libc:: ptsname ( fd. as_raw_fd ( ) ) } ;
139
+ pub unsafe fn ptsname ( fd : & PtyMaster ) -> Result < String > {
140
+ let name_ptr = libc:: ptsname ( fd. as_raw_fd ( ) ) ;
135
141
if name_ptr. is_null ( ) {
136
142
return Err ( Error :: last ( ) . into ( ) ) ;
137
143
}
138
144
139
- let name = unsafe {
140
- CStr :: from_ptr ( name_ptr)
141
- } ;
145
+ let name = CStr :: from_ptr ( name_ptr) ;
142
146
Ok ( name. to_string_lossy ( ) . into_owned ( ) )
143
147
}
144
148
@@ -187,7 +191,7 @@ pub fn unlockpt(fd: &PtyMaster) -> Result<()> {
187
191
188
192
/// Create a new pseudoterminal, returning the slave and master file descriptors
189
193
/// in `OpenptyResult`
190
- /// (see [openpty](http://man7.org/linux/man-pages/man3/openpty.3.html)).
194
+ /// (see [openpty](http://man7.org/linux/man-pages/man3/openpty.3.html)).
191
195
///
192
196
/// If `winsize` is not `None`, the window size of the slave will be set to
193
197
/// the values in `winsize`. If `termios` is not `None`, the pseudoterminal's
0 commit comments