refactoring: use errno symbols instead of hard value and extract functions