Search packages, repositories and app categories

Package detailsv6.5.4

posix

Exposes the POSIX api on OSx and Linux

AndroidiOSmacOSWindowsLinux
30-day downloads
9.4M
Likes
12
Pub points
160

Install package

flutter pub add posix

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The posix package provides access to POSIX system APIs on macOS and Linux, enabling low-level system operations such as file manipulation, process control, and signal handling. It is designed for desktop applications requiring direct interaction with the underlying operating system. The package exposes native POSIX functions through a Dart interface, making it suitable for advanced system programming tasks. It supports macOS, Linux, Windows, Android, and iOS platforms, though full POSIX functionality is primarily available on macOS and Linux. This package is ideal for developers building tools that need fine-grained control over system resources.

Use cases

  • System-level file operations
  • Process and thread management
  • Signal handling in desktop apps
  • Cross-platform system utilities
  • Low-level OS interactions

Key features

  • Access to native POSIX APIs
  • Support for macOS and Linux
  • Cross-platform compatibility
  • Dart-friendly wrapper for system calls
  • Lightweight and focused design

Suitable for

  • Desktop application developers
  • System tool creators
  • Advanced Flutter users
  • Developers needing OS-level access
  • Tools requiring process isolation

Considerations

  • Limited functionality on non-POSIX platforms
  • Requires platform-specific knowledge
  • Not intended for mobile app core logic
  • May require elevated permissions
  • Best suited for desktop environments only

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Provides Dart access to the POSIX api for MacOS and Linux system.


import 'package:posix/posix.dart';

int uid = getuid();

Contributing

Dart types only

The api should only expose dart types. Any C types MUST be translated to dart types before being returned.

setters and getters

One of the first questsion is to whether we should use Dart's settings and getters:

e.g.


// getuid
int uid = getuid;

or

int uid = getuid();


/// setuid

uid = myuid;

or 

setuid = uid;

or

setuid(uid);

My initial thoughts is to make the api identical to the posix api which would mean that we don't use Dart setters and getters.

error returns

Do we return error no.s or do we throw.

As Dart is a modern language it uses Exception whereas posix returns error codes.

Often posix will return null and then expect you to make a separate call to 'errorno' to get the actual error no.

I'm inclined to bring the api that we expose into the modern world.

So I'm proposing that if an posix api returns an error that we throw a PosixException with a message and error code.

Adding additional functions

The process of adding additional functions is:

  1. Install ffigen
dart pub global activate ffigen
  1. Run the ffigen setup.

The paths may be different on your system. Search for clang-c/Index.h

sudo apt-get install libclang-dev
dart pub run ffigen:setup -I/usr/lib/llvm-11/include -L/usr/lib/llvm-11/lib
  1. find the required posix header file

  2. use ffigen to create the initial dart file from the header.

    • add your header file to ffigen.yaml
  3. Run ffigen

dart pub run ffigen  --config ffigen/linux.yaml 
  1. convert each method to take/return dart types.

Categories

Dependencies

Dependency list 3 items

Source repository

Projects using this package