diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/lib/System/Argv0.hs b/lib/System/Argv0.hs
new file mode 100644
--- /dev/null
+++ b/lib/System/Argv0.hs
@@ -0,0 +1,63 @@
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE ForeignFunctionInterface #-}
+
+module System.Argv0
+	( getArgv0
+	) where
+
+import           Prelude hiding (FilePath)
+
+import           Foreign
+import           Foreign.C
+#if defined(mingw32_HOST_OS) && __GLASGOW_HASKELL__ >= 702
+import           GHC.Environment (getFullArgs)
+#endif
+
+import           Filesystem.Path (FilePath)
+import           Filesystem.Path.CurrentOS (decodeString)
+
+-- | Get @argv[0]@ as a 'FilePath'. This is how the program was invoked, and
+-- might not correspond to any actual file.
+--
+-- Use this instead of @System.Environment.getProgName@ if you want the full
+-- path, and not just the last component.
+getArgv0 :: IO FilePath
+
+#if defined(mingw32_HOST_OS) && __GLASGOW_HASKELL__ >= 702
+getArgv0 = do
+	m_argv0 <- getWin32ProgArgv0
+	argv0 <- maybe (fmap head getFullArgs) return m_argv0
+	return (decodeString argv0)
+
+getWin32ProgArgv0 :: IO (Maybe String)
+getWin32ProgArgv0 =
+	alloca $ \p_argc ->
+	alloca $ \p_argv -> do
+		c_getWin32ProgArgv p_argc p_argv
+		argv <- peek p_argv
+		if argv == nullPtr
+			then return Nothing
+			else do
+				argv0 <- peekCWString =<< peekElemOff argv 0
+				return (Just argv0)
+
+foreign import ccall unsafe "getWin32ProgArgv"
+	c_getWin32ProgArgv :: Ptr CInt -> Ptr (Ptr CWString) -> IO ()
+
+#else
+getArgv0 =
+	alloca $ \p_argc ->
+	alloca $ \p_argv -> do
+		c_getProgArgv p_argc p_argv
+		argv <- peek p_argv
+#ifdef mingw32_HOST_OS
+		argv0 <- peekCString =<< peekElemOff argv 0
+#else
+		argv0 <- peekCAString =<< peekElemOff argv 0
+#endif
+		return (decodeString argv0)
+
+foreign import ccall unsafe "getProgArgv"
+	c_getProgArgv :: Ptr CInt -> Ptr (Ptr CString) -> IO ()
+
+#endif
diff --git a/license.txt b/license.txt
new file mode 100644
--- /dev/null
+++ b/license.txt
@@ -0,0 +1,22 @@
+Copyright (c) 2011 John Millikin
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
diff --git a/system-argv0.cabal b/system-argv0.cabal
new file mode 100644
--- /dev/null
+++ b/system-argv0.cabal
@@ -0,0 +1,40 @@
+name: system-argv0
+version: 0.1
+license: MIT
+license-file: license.txt
+author: John Millikin <jmillikin@gmail.com>
+maintainer: John Millikin <jmillikin@gmail.com>
+build-type: Simple
+cabal-version: >= 1.6
+category: System
+stability: experimental
+homepage: https://john-millikin.com/software/hs-argv0/
+bug-reports: mailto:jmillikin@gmail.com
+
+synopsis: Get @argv[0]@ as a FilePath.
+description:
+  Get @argv[0]@ as a FilePath. This is how the program was invoked, and might
+  not correspond to any actual file.
+  .
+  Use this instead of @System.Environment.getProgName@ if you want the full
+  path, and not just the last component.
+
+source-repository head
+  type: bazaar
+  location: https://john-millikin.com/software/hs-argv0/
+
+source-repository this
+  type: bazaar
+  location: https://john-millikin.com/branches/hs-argv0/0.1/
+  tag: system-argv0_0.1
+
+library
+  hs-source-dirs: lib
+  ghc-options: -Wall -O2
+
+  build-depends:
+      base >= 4.0 && < 5.0
+    , system-filepath >= 0.3.1 && < 0.5
+
+  exposed-modules:
+    System.Argv0
