Skip to content

Commit f46cb40

Browse files
committed
ffi: avoid publicly exporting unsafe ioctl wrappers
We only want to export the safe wrappers around these. Solve this by putting the generated pub functions inside an unexported module. Signed-off-by: Paul Osborne <[email protected]>
1 parent 9fb7866 commit f46cb40

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/ffi.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,18 @@ struct i2c_rdwr_ioctl_data {
171171
nmsgs: u32,
172172
}
173173

174-
ioctl!(bad write_int ioctl_set_i2c_slave_address with I2C_SLAVE);
175-
ioctl!(bad write_ptr ioctl_i2c_smbus with I2C_SMBUS; i2c_smbus_ioctl_data);
174+
mod ioctl {
175+
use super::{I2C_SLAVE, I2C_SMBUS};
176+
pub use super::i2c_smbus_ioctl_data;
177+
178+
ioctl!(bad write_int set_i2c_slave_address with I2C_SLAVE);
179+
ioctl!(bad write_ptr i2c_smbus with I2C_SMBUS; i2c_smbus_ioctl_data);
180+
}
181+
176182

177183
pub fn i2c_set_slave_address(fd: RawFd, slave_address: u16) -> Result<(), nix::Error> {
178184
try!(unsafe {
179-
ioctl_set_i2c_slave_address(fd, slave_address as i32)
185+
ioctl::set_i2c_slave_address(fd, slave_address as i32)
180186
});
181187
Ok(())
182188
}
@@ -195,7 +201,7 @@ unsafe fn i2c_smbus_access(fd: RawFd,
195201
};
196202

197203
// remove type information
198-
ioctl_i2c_smbus(fd, &mut args).map(drop)
204+
ioctl::i2c_smbus(fd, &mut args).map(drop)
199205
}
200206

201207
#[inline]

0 commit comments

Comments
 (0)